-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
71 lines (56 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const album = document.querySelector('.album');
const play = document.querySelector('.play');
const outline = document.querySelector('.moving-outline circle');
const video = document.querySelector('.video-container video');
const sounds = document.querySelectorAll('.sound-selection button');
const timeDisplay = document.querySelector('.time-display');
const timeSelect = document.querySelectorAll('.time-select button');
const outlineLength = outline.getTotalLength();
const app = () => {
let duration = 600;
outline.style.strokeDasharray = outlineLength;
outline.style.strokeDashoffset = outlineLength;
sounds.forEach(sound => {
sound.addEventListener('click', function() {
album.src = this.getAttribute('data-sound');
video.src = this.getAttribute('data-video');
checkPlaying(album);
})
})
play.addEventListener('click', () => {
checkPlaying(album)
});
timeSelect.forEach(option => {
option.addEventListener('click', function() {
duration = this.getAttribute('data-time');
timeDisplay.textContent = `${Math.floor(duration / 60)} : 00`
})
})
const checkPlaying = album => {
if(album.paused) {
album.play()
video.play()
play.src = './pause.svg';
} else {
album.pause()
video.pause()
play.src = './play.svg';
}
}
album.ontimeupdate = () => {
let currentTime = album.currentTime;
let elapsed = duration - currentTime;
let seconds = Math.floor(elapsed % 60);
let minutes = Math.floor(elapsed / 60);
let progress = outlineLength - (currentTime / duration) * outlineLength;
outline.style.strokeDashoffset = progress;
timeDisplay.textContent = `${minutes}:${seconds}`;
if (currentTime >= duration) {
album.pause();
album.currentTime = 0;
play.src = './play.svg';
video.pause()
}
}
}
app();