-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
69 lines (60 loc) · 2.21 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
const app = () => {
const song = document.querySelector('.song');
const play = document.querySelector('.play');
const appElement =document.querySelector('.app');
const video =document.querySelector('.video-container video')
//sounds
const songs = document.querySelectorAll('.sound-picker button');
//Time Display
const timeDisplay = document.querySelector('.time-display')
const timeSelect = document.querySelectorAll('.time-selector button')
//Duration(you can chosse any duration)
let fakeDuration = 600;
//play sounds
play.addEventListener('click', () => {
playingSongs(song);
});
//Create a function specific to stop and play songs
const playingSongs = song => {
if (song.paused) {
song.play();
play.src = "./assets/pause.svg";
} else {
song.pause()
play.src = "./assets/play.svg";
}
};
//Animate the time
song.addEventListener('timeupdate',function (){
test();
});
// Create a function that will animate time
const test = ()=>{
let currentTime =song.currentTime;
let elapsed = fakeDuration - currentTime;
let seconds=Math.floor(parseInt(elapsed) % 60);
let minutes =Math.floor(parseInt(elapsed) / 60);
timeDisplay.innerText = `${minutes}:${seconds}`;
if (currentTime >= fakeDuration){
currentTime = 0;
song.pause();
play.src = "./assets/play.svg";
};
}
//select sounds
songs.forEach(sound=>{
sound.addEventListener('click',function(){
song.src=this.getAttribute('data-sound');
appElement.style.backgroundImage="url('https://d39ghehfp8sbx4.cloudfront.net/media/img/1/95ecdee2-6dbb-4614-9c0e-aa88a3489769-1400.jpg?placeid=948&name=Barceloneta%20Beach&lat=41.378372&lng=2.192468')";
playingSongs(song);
});
});
//select time
timeSelect.forEach(option=>{
option.addEventListener('click',function(){
fakeDuration=this.getAttribute("data-time")
timeDisplay.innerText = `${Math.floor(fakeDuration / 60)}:${Math.floor(fakeDuration % 60)}`
});
});
}
app();