-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeditation.js
More file actions
69 lines (62 loc) · 1.93 KB
/
Copy pathmeditation.js
File metadata and controls
69 lines (62 loc) · 1.93 KB
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 timer = document.querySelector('.timer')
const timeBtns = document.querySelectorAll('.mins')
const soundBtns = document.querySelectorAll('.background button')
const video = document.querySelector('.bg-video video')
const music = document.querySelector('.music')
const play = document.querySelector('.play')
const pause = document.querySelector('.pause')
const movingOutline = document.querySelector('.moving-outline circle')
const trackOutline = document.querySelector('.track-outline-breath circle')
const text = document.querySelector('.text')
let duration = 600
function resetChoice(){
play.classList.remove('hide')
pause.classList.remove('show')
video.pause()
music.pause()
music.currentTime = 0
}
soundBtns.forEach(button => {
button.addEventListener('click', function (){
resetChoice();
video.src=this.dataset.video
music.src=this.dataset.sound
})
})
play.addEventListener('click', function (){
video.play()
music.play()
play.classList.add('hide')
pause.classList.add('show')
})
pause.addEventListener('click', function (){
video.pause()
music.pause()
play.classList.remove('hide')
pause.classList.remove('show')
})
const movingOutlineLength = movingOutline.getTotalLength();
movingOutline.style.strokeDasharray = movingOutlineLength;
timeBtns.forEach(button => {
button.addEventListener('click', () => {
resetChoice()
music.currentTime = 0
duration = button.dataset.time
})
})
music.ontimeupdate = function (){
let currentTime = music.currentTime
let elapsed = duration - currentTime
let seconds = Math.floor(elapsed % 60)
let minutes = Math.floor(elapsed / 60)
let progress = movingOutlineLength - (currentTime / duration) * movingOutlineLength
movingOutline.style.strokeDashoffset = progress;
if (seconds < 10) {
seconds = '0' + seconds
}
if (minutes <= 0 && seconds <= 0) {
resetChoice()
timer.textContent = '0.00'
}
timer.textContent = `${minutes}:${seconds}`
}