/
main.js
60 lines (44 loc) · 1.39 KB
/
main.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
var updateUIInterval;
var isRunning = false;
var seconds = 0;
var minutes = 0;
var mainBeat = new Howl({
src: ['sound/mainbeat.wav']
});
var otherBeat = new Howl({
src: ['sound/otherbeat.wav']
});
function updateUI() {
seconds++;
if (seconds % 5 === 0) {
mainBeat.play()
} else {
otherBeat.play()
}
var secondString = '00';
var minuteString = '00';
if (seconds === 60) {
minutes++;
seconds = 0;
}
secondString = (seconds < 10) ? `0${seconds}` : `${seconds}`
minuteString = (minutes < 10) ? `0${minutes}` : `${minutes}`
var timerString = `${minuteString}:${secondString}`;
console.log(timerString);
document.getElementById('timer').innerText = `${timerString}`;
}
document.getElementById('breathe').addEventListener('click', () => {
isRunning = !isRunning
if (isRunning) {
document.getElementById('breathe').innerText = "Stop"
document.getElementById('bubble').style.animation = 'mover 10s infinite ease-in-out'
updateUIInterval = setInterval(updateUI, 1000);
} else {
document.getElementById('breathe').innerText = "Breathe"
document.getElementById('bubble').style.animation = 'none'
document.getElementById('timer').innerText = `00:00`;
seconds = 0;
minutes = 0;
clearInterval(updateUIInterval);
}
});