-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
87 lines (65 loc) · 2.41 KB
/
script.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const app = () => {
const video = document.querySelector(".default-video video");
const song = document.querySelector(".song");
const play = document.querySelector(".play");
const outline = document.querySelector(".moving-outline circle");
//time display
const timeDisplay = document.querySelector(".time-display");
const timeSelect = document.querySelectorAll(".time-selector button");
//sounds
const sounds = document.querySelectorAll(".sound-selector button");
//length of the outline
const outlineLength= outline.getTotalLength();
outline.style.strokeDasharray = outlineLength;
outline.style.strokeDashoffset = outlineLength;
//play duration
var playDuration = 600;
// select time
timeSelect.forEach(option => {
option.addEventListener( "click", function(){
playDuration = this.getAttribute("data-time");
timeDisplay.textContent = `${Math.floor(playDuration / 60)}:${Math.floor(playDuration % 60)}`;
});
});
//play & pause event
play.addEventListener("click" , () => {
playing(song);
});
const playing = song =>{
if(song.paused){
song.play();
video.play();
play.src = "images/pause.png";
}else{
song.pause();
video.pause();
play.src = "images/play.png";
}
};
//animate the circle
song.ontimeupdate = () => {
let currentTime = song.currentTime;
let elapsed = playDuration - currentTime;
let seconds = Math.floor(elapsed % 60 );
let minutes = Math.floor(elapsed /60);
let progress = outlineLength - (currentTime/playDuration) * outlineLength;
outline.style.strokeDashoffset = progress ;
// Animate time text
timeDisplay.textContent = `${minutes}:${seconds}` ;
if (currentTime >= playDuration){
song.pause();
video.pause();
song.currentTime = 0 ;
play.src = "images/play.png";
};
};
// select sound
sounds.forEach( sound => {
sound.addEventListener("click", function(){
video.src= this.getAttribute("data-video");
song.src= this.getAttribute("data-sound");
playing(song);
});
});
};
app();