Skip to content

Commit d76d2b9

Browse files
committed
day 27
1 parent e3b7c0a commit d76d2b9

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

27 - Click and Drag/css/style.css

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
html {
2+
box-sizing: border-box;
3+
background: url('https://source.unsplash.com/NFs6dRTBgaM/2000x2000') fixed;
4+
background-size: cover;
5+
}
6+
7+
*, *:before, *:after {
8+
box-sizing: inherit;
9+
}
10+
11+
body {
12+
min-height: 100vh;
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
font-family: sans-serif;
17+
font-size: 20px;
18+
margin: 0;
19+
}
20+
21+
.items {
22+
height: 800px;
23+
padding: 100px;
24+
width: 100%;
25+
border: 1px solid white;
26+
overflow-x: scroll;
27+
overflow-y: hidden;
28+
white-space: nowrap;
29+
user-select: none;
30+
cursor: pointer;
31+
transition: all 0.2s;
32+
transform: scale(0.98);
33+
will-change: transform;
34+
position: relative;
35+
background: rgba(255,255,255,0.1);
36+
font-size: 0;
37+
perspective: 500px;
38+
}
39+
40+
.items.active {
41+
background: rgba(255,255,255,0.3);
42+
cursor: grabbing;
43+
cursor: -webkit-grabbing;
44+
transform: scale(1);
45+
}
46+
47+
.item {
48+
width: 200px;
49+
height: calc(100% - 40px);
50+
display: inline-flex;
51+
align-items: center;
52+
justify-content: center;
53+
font-size: 80px;
54+
font-weight: 100;
55+
color: rgba(0,0,0,0.15);
56+
box-shadow: inset 0 0 0 10px rgba(0,0,0,0.15);
57+
}
58+
59+
.item:nth-child(9n+1) { background: dodgerblue;}
60+
.item:nth-child(9n+2) { background: goldenrod;}
61+
.item:nth-child(9n+3) { background: paleturquoise;}
62+
.item:nth-child(9n+4) { background: gold;}
63+
.item:nth-child(9n+5) { background: cadetblue;}
64+
.item:nth-child(9n+6) { background: tomato;}
65+
.item:nth-child(9n+7) { background: lightcoral;}
66+
.item:nth-child(9n+8) { background: darkslateblue;}
67+
.item:nth-child(9n+9) { background: rebeccapurple;}
68+
69+
.item:nth-child(even) { transform: scaleX(1.31) rotateY(40deg); }
70+
.item:nth-child(odd) { transform: scaleX(1.31) rotateY(-40deg); }

27 - Click and Drag/js/script.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const slider = document.querySelector(".items");
2+
let isDown = false;
3+
let startX;
4+
let scrollLeft;
5+
6+
slider.addEventListener("mousedown", (e) => {
7+
isDown = true;
8+
slider.classList.add("active");
9+
startX = e.pageX - slider.offsetLeft;
10+
scrollLeft = slider.scrollLeft;
11+
// console.log(startX);
12+
});
13+
slider.addEventListener("mouseleave", () => {
14+
isDown = false;
15+
slider.classList.remove("active");
16+
});
17+
slider.addEventListener("mouseup", () => {
18+
isDown = false;
19+
slider.classList.remove("active");
20+
});
21+
slider.addEventListener("mousemove", (e) => {
22+
if (!isDown) return;
23+
// console.count(isDown);
24+
// console.log(startX);
25+
e.preventDefault();
26+
const x = e.pageX - slider.offsetLeft;
27+
// console.log({ x, startX });
28+
const walk = (x - startX) * 3;
29+
console.log(walk);
30+
slider.scrollLeft = scrollLeft - walk;
31+
});

0 commit comments

Comments
 (0)