Skip to content

Commit 2e1234b

Browse files
committed
add day 26~30
1 parent 2a5b549 commit 2e1234b

File tree

14 files changed

+256
-22
lines changed

14 files changed

+256
-22
lines changed

24 - Sticky Nav/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# JS30-Day24-Sticky Nav
2-
實作一個常見固定在網頁上方的 nav bar
2+
實作一個常見固定在網頁上方的 nav bar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# JS30-Day25-Stripe Follow Along Dropdown
2+
一個滑鼠 hover 到超連結後會出現下拉選單的實作

26 - Stripe Follow Along Nav/index-Harry.html

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,43 @@ <h2>Cool</h2>
233233
</style>
234234

235235
<script>
236+
const triggers = document.querySelectorAll('.cool > li');
237+
const background = document.querySelector('.dropdownBackground');
238+
const nav = document.querySelector('.top');
239+
240+
function handleEnter() {
241+
this.classList.add('trigger-enter');
242+
// 有 trigger-enter class 才觸發後面的程式碼
243+
setTimeout(() => { this.classList.contains('trigger-enter') && this.classList.add('trigger-enter-active'); }, 150);
244+
background.classList.add('open');
245+
246+
const dropdown = this.querySelector('.dropdown');
247+
const dropdownCoords = dropdown.getBoundingClientRect();
248+
// 為了減去 nav 元素上面的元素所佔的位置,所以也要取到 nav 的位置並減掉它
249+
const navCoords = nav.getBoundingClientRect();
250+
251+
const coords = {
252+
width: dropdownCoords.width,
253+
height: dropdownCoords.height,
254+
top: dropdownCoords.top - navCoords.top,
255+
left: dropdownCoords.left - navCoords.left
256+
}
257+
258+
background.style.setProperty('width', `${coords.width}px`);
259+
background.style.setProperty('height', `${coords.height}px`);
260+
// translate(x, y)
261+
background.style.setProperty('transform', `translate(${coords.left}px, ${coords.top}px)`);
262+
}
263+
264+
function handleLeave() {
265+
this.classList.remove('trigger-enter', 'trigger-enter-active');
266+
background.classList.remove('open');
267+
}
268+
269+
triggers.forEach(trigger => trigger.addEventListener('mouseenter', handleEnter));
270+
triggers.forEach(trigger => trigger.addEventListener('mouseleave', handleLeave));
236271
</script>
237272

238273
</body>
239274

240-
</html>
275+
</html>

27 - Click and Drag/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# JS30-Day27-Click and Drag to Scroll
2+
一個滑鼠點擊網頁後可以左右拉動的實作
3+
4+
## 重點整理
5+
### 1. e.scrollLeft
6+
代表元素左邊和橫軸滾動條的距離
7+
8+
MDN 介紹:
9+
https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollLeft

27 - Click and Drag/index-Harry.html

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,39 @@
3737
</div>
3838

3939
<script>
40+
const slider = document.querySelector('.items');
41+
let isDown = false,
42+
startX,
43+
scrollLeft;
44+
45+
slider.addEventListener('mousedown', (e) => {
46+
isDown = true;
47+
slider.classList.add('active')
48+
// 設定目前頁面距離
49+
startX = e.clientX - slider.offsetLeft;;
50+
// 設定卷軸左距
51+
scrollLeft = slider.scrollLeft;
52+
});
53+
54+
slider.addEventListener('mouseleave', () => {
55+
isDown = false;
56+
slider.classList.remove('active');
57+
});
58+
59+
slider.addEventListener('mouseup', () => {
60+
isDown = false;
61+
slider.classList.remove('active');
62+
})
63+
64+
slider.addEventListener('mousemove', (e) => {
65+
if(!isDown) return;
66+
e.preventDefault();
67+
const x = e.clientX;
68+
const walkDistance = (x - startX) * 3;
69+
slider.scrollLeft = scrollLeft - walkDistance;
70+
})
4071
</script>
4172

4273
</body>
4374

44-
</html>
75+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# JS30-Day28-Video Speed Controller UI
2+
實作一個可以控制影片撥放速度的控制條

28 - Video Speed Controller/index-FINISHED.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<div class="wrapper">
1111
<video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop controls></video>
12-
<p>
1312
<div class="speed">
1413
<div class="speed-bar"></div>
1514
</div>
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
43
<head>
54
<meta charset="UTF-8">
65
<title>Video Speed Scrubber</title>
76
<link rel="stylesheet" href="style.css">
87
</head>
9-
108
<body>
119

1210
<div class="wrapper">
13-
<video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop
14-
controls></video>
11+
<video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop controls></video>
1512
<div class="speed">
1613
<div class="speed-bar"></div>
1714
</div>
1815
</div>
1916

2017
<script>
18+
const speed = document.querySelector('.speed');
19+
const bar = speed.querySelector('.speed-bar');
20+
const video = document.querySelector('.flex');
21+
22+
function handleMove(e) {
23+
const percent = (e.clientY - this.offsetTop) / this.offsetHeight,
24+
min = 0.5,
25+
max = 4;
26+
height = Math.floor(percent * 100) + '%';
27+
let speed = percent * (max - min) + min;
28+
29+
bar.style.height = height;
30+
bar.textContent = speed.toFixed(2) + 'x';
31+
video.playbackRate = speed;
32+
}
33+
34+
speed.addEventListener('mousemove', handleMove);
2135
</script>
2236
</body>
2337

24-
</html>
38+
</html>

29 - Countdown Timer/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# JS30-Day29-Countdown Clock
2+
建立一個倒數計時器
3+
4+
## 重點整理
5+
### 1. new Date() vs. Date.now()
6+
透過這個實作重新複習一次兩者取出的值
7+
8+
`new Date()` 取出的是有星期幾,年月日幾點幾分幾秒的格式,而 `Date.now()` 取出的是從現在的時間到 1970 年 1 月 1 日開始的毫秒數值
9+
![](https://i.imgur.com/Yh6oBu3.png)
10+
11+
`new Date()` 內也可以放置 timestamp,取得過去的時間
12+
![](https://i.imgur.com/8dvB5rZ.png)
13+
14+
### 2. 可以使用屬性 name 來綁定監聽事件
15+
```html
16+
<form name="customForm" id="custom">
17+
<input type="text" name="minutes" placeholder="Enter Minutes">
18+
</form>
19+
```
20+
21+
這裡使用表單名字 customForm 綁定監聽事件
22+
```javascript
23+
document.customForm.addEventListener('submit', function(e) {
24+
e.preventDefault();
25+
// ...
26+
});
27+
```

29 - Countdown Timer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ <h1 class="display__time-left"></h1>
2424
</div>
2525
</div>
2626

27-
<script src="scripts-START.js"></script>
27+
<script src="scripts-Harry.js"></script>
2828
</body>
2929
</html>

0 commit comments

Comments
 (0)