Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7572a9b

Browse files
committed
lesson wesbos#11 done
1 parent d3feeb4 commit 7572a9b

File tree

5 files changed

+74
-13
lines changed

5 files changed

+74
-13
lines changed

08 - Fun with HTML5 Canvas/index-START.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
ctx.strokeStyle = `hsl(${hsl}, 100%, 50%)`;
2525
ctx.lineCap = "round";
2626
ctx.lineJoin = "round";
27-
ctx.lineWidth = 20;
27+
// ctx.lineWidth = 20;
2828
ctx.beginPath();
2929
ctx.moveTo(lastX, lastY);
3030
ctx.lineTo(e.offsetX, e.offsetY);
@@ -36,15 +36,15 @@
3636
hsl = 0;
3737
}
3838
//
39-
// if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
40-
// dir = !dir;
41-
// }
39+
if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
40+
dir = !dir;
41+
}
4242

43-
// if (dir) {
44-
// ctx.lineWidth++;
45-
// } else {
46-
// ctx.lineWidth--;
47-
// }
43+
if (dir) {
44+
ctx.lineWidth++;
45+
} else {
46+
ctx.lineWidth--;
47+
}
4848

4949
}
5050
canvas.addEventListener('mousedown', (e) => {

09 - Dev Tools Domination/index-START.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
console.assert(1 !== 1, 'wrong');
3939

4040
// clearing
41-
console.clear();
41+
// console.clear();
4242

4343
// Viewing DOM Elements
4444
const p = document.querySelector('p');

11 - Custom Video Player/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
<meta charset="UTF-8">
55
<title>HTML Video Player</title>
66
<link rel="stylesheet" href="style.css">
7+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
78
</head>
89
<body>
9-
10+
1011
<div class="player">
1112
<video class="player__video viewer" src="652333414.mp4"></video>
1213

1314
<div class="player__controls">
1415
<div class="progress">
1516
<div class="progress__filled"></div>
1617
</div>
17-
<button class="player__button toggle" title="Toggle Play"></button>
18+
<button class="player__button toggle" title="Toggle Play"><i class="fas fa-play"></i></button>
1819
<input type="range" name="volume" class="player__slider" min="0" max="1" step="0.05" value="1">
1920
<input type="range" name="playbackRate" class="player__slider" min="0.5" max="2" step="0.1" value="1">
2021
<button data-skip="-10" class="player__button">« 10s</button>

11 - Custom Video Player/scripts.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// get elements
2+
const player = document.querySelector('.player');
3+
const video = player.querySelector('.viewer');
4+
const progress = player.querySelector('.progress');
5+
const progressBar = player.querySelector('.progress__filled');
6+
const toggle = player.querySelector('.toggle');
7+
const sliders = player.querySelectorAll('.player__slider');
8+
const skipButtons = player.querySelectorAll('[data-skip]');
9+
10+
console.dir(video);
11+
12+
// add play/pause method
13+
function playerToggle() {
14+
const state = video.paused ? 'play' : 'pause';
15+
video[state]();
16+
}
17+
18+
function updateButton() {
19+
const state = video.paused ? '<i class="fas fa-play"></i>' : '<i class="fas fa-pause"></i>';
20+
toggle.innerHTML = state;
21+
}
22+
23+
function skip() {
24+
video.currentTime += +this.dataset.skip;
25+
}
26+
27+
function rangeUpdate() {
28+
video[this.name] = this.value;
29+
}
30+
31+
function handleProgress() {
32+
const prog = (video.currentTime / video.duration) * 100;
33+
progressBar.style.flexBasis = `${prog}%`;
34+
}
35+
36+
function scrub(e) {
37+
const percent = (e.offsetX / progress.offsetWidth) * 100;
38+
const time = (percent * video.duration) / 100;
39+
video.currentTime = time;
40+
41+
}
42+
43+
// hook event listeners
44+
video.addEventListener('click', playerToggle);
45+
video.addEventListener('play', updateButton);
46+
video.addEventListener('pause', updateButton);
47+
video.addEventListener('timeupdate', handleProgress);
48+
49+
toggle.addEventListener('click', playerToggle);
50+
51+
skipButtons.forEach(skipButton => skipButton.addEventListener('click', skip));
52+
sliders.forEach(slider => slider.addEventListener('change', rangeUpdate));
53+
54+
let draggin = false;
55+
progress.addEventListener('click', scrub);
56+
progress.addEventListener('mousemove', (e) => draggin && scrub(e));
57+
58+
progress.addEventListener('mousedown', () => draggin = true);
59+
progress.addEventListener('mouseup', () => draggin = false);
60+

11 - Custom Video Player/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ body {
101101
width: 50%;
102102
background: #ffc600;
103103
flex: 0;
104-
flex-basis: 50%;
104+
/* flex-basis: 50%; */
105105
}
106106

107107
/* unholy css to style input type="range" */

0 commit comments

Comments
 (0)