-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (34 loc) · 1.12 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
const text = document.querySelector('.text')
const circle = document.querySelector('.circle')
const playBtn = document.querySelector('.fa-play')
const pauseBtn = document.querySelector('.fa-pause')
const bgMusic = document.querySelector('#bgMusic')
const totalTime = 14000
const breatheTime = (totalTime / 7) * 2.5
const holdTime = (totalTime / 7)
breatheAnimation ()
playBtn.addEventListener('click', playMusic)
pauseBtn.addEventListener('click', pauseMusic)
function breatheAnimation () {
text.innerHTML = 'Inhale'
circle.className = 'circle grow'
text.className = ' text grow'
setTimeout(() => {
text.innerHTML = 'Hold'
setTimeout(() => {
text.innerHTML = 'Exhale'
circle.className = 'circle shrink'
text.className = ' text shrink'
setTimeout(() => {
text.innerHTML = 'Hold'
}, breatheTime)
}, holdTime)
}, breatheTime)
}
setInterval(breatheAnimation, totalTime)
function playMusic() {
bgMusic.play()
}
function pauseMusic() {
bgMusic.pause()
}