Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3792342

Browse files
Day 27 - Click and Drag
1 parent 99f5edc commit 3792342

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

‎27_day/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Click and Drag</title>
6+
<link rel="stylesheet" href="main.css">
7+
</head>
8+
<body>
9+
<div class="items">
10+
<div class="item item1">01</div>
11+
<div class="item item2">02</div>
12+
<div class="item item3">03</div>
13+
<div class="item item4">04</div>
14+
<div class="item item5">05</div>
15+
<div class="item item6">06</div>
16+
<div class="item item7">07</div>
17+
<div class="item item8">08</div>
18+
<div class="item item9">09</div>
19+
<div class="item item10">10</div>
20+
<div class="item item11">11</div>
21+
<div class="item item12">12</div>
22+
<div class="item item13">13</div>
23+
<div class="item item14">14</div>
24+
<div class="item item15">15</div>
25+
<div class="item item16">16</div>
26+
<div class="item item17">17</div>
27+
<div class="item item18">18</div>
28+
<div class="item item19">19</div>
29+
<div class="item item20">20</div>
30+
<div class="item item21">21</div>
31+
<div class="item item22">22</div>
32+
<div class="item item23">23</div>
33+
<div class="item item24">24</div>
34+
<div class="item item25">25</div>
35+
</div>
36+
<script type="text/javascript" src="main.js">
37+
38+
</script>
39+
40+
</body>
41+
</html>

‎27_day/main.css

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
box-shadow: 0 0 10px 7px rgba(0, 0, 0, 0.09);
27+
overflow-x: scroll;
28+
overflow-y: hidden;
29+
white-space: nowrap;
30+
user-select: none;
31+
cursor: pointer;
32+
transition: all 0.2s;
33+
transform: scale(0.98);
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) {
60+
background: dodgerblue;
61+
}
62+
63+
.item:nth-child(9n+2) {
64+
background: goldenrod;
65+
}
66+
67+
.item:nth-child(9n+3) {
68+
background: paleturquoise;
69+
}
70+
71+
.item:nth-child(9n+4) {
72+
background: gold;
73+
}
74+
75+
.item:nth-child(9n+5) {
76+
background: cadetblue;
77+
}
78+
79+
.item:nth-child(9n+6) {
80+
background: tomato;
81+
}
82+
83+
.item:nth-child(9n+7) {
84+
background: lightcoral;
85+
}
86+
87+
.item:nth-child(9n+8) {
88+
background: darkslateblue;
89+
}
90+
91+
.item:nth-child(9n+9) {
92+
background: rebeccapurple;
93+
}
94+
95+
.item:nth-child(even) {
96+
transform: scaleX(1.31) rotateY(40deg);
97+
}
98+
99+
.item:nth-child(odd) {
100+
transform: scaleX(1.31) rotateY(-40deg);
101+
}
102+
103+
.wrap {
104+
width: auto;
105+
border: 2px solid green;
106+
height: 100%;
107+
}

‎27_day/main.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
});
12+
13+
slider.addEventListener('mouseleave', () => {
14+
isDown = false;
15+
slider.classList.remove('active');
16+
});
17+
18+
slider.addEventListener('mouseup', () => {
19+
isDown = false;
20+
slider.classList.remove('active');
21+
});
22+
23+
slider.addEventListener('mousemove', (e) => {
24+
if (!isDown)
25+
return; // stop the fn from running
26+
e.preventDefault();
27+
const x = e.pageX - slider.offsetLeft;
28+
const walk = (x - startX) * 3;
29+
slider.scrollLeft = scrollLeft - walk;
30+
});

‎27_day/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "gum",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "scripts.js",
6+
"scripts": {
7+
"start" : "browser-sync start --directory --server --files '*.css, *.html, *.js'"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"devDependencies": {
12+
"browser-sync": "^2.12.5"
13+
}
14+
}

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,6 @@ Learned about `Event.stopPropagation()` & `EventTarget.addEventListener()` boole
147147

148148
### Day 26: 13 Jul 2018
149149
It was super-fun learning abt this really slick "follow along" nav found on Stripe's pricing page.
150+
151+
### Day 27: 14 Jul 208
152+
Understood the basics behind the "Click and Drag to Scroll" challenge. element.offsetLeft play a great role in this logic.

‎index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<a class="active" href="./24_day/index.html">24 Day</a>
3636
<a class="active" href="./25_day/index.html">25 Day</a>
3737
<a class="active" href="./26_day/index.html">26 Day</a>
38+
<a class="active" href="./27_day/index.html">27 Day</a>
3839
</div>
3940
</body>
4041

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /