-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
32 lines (28 loc) · 808 Bytes
/
app.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
var water = document.querySelector('.water');
var urine = document.querySelector('.urine');
var flushBtn = document.querySelector('.flush');
var isFlushing = false;
var flushingAudio = new Audio('flushing.mp3')
function pee() {
water.classList.add('pee');
urine.classList.add('pee');
if (isFlushing) {
setTimeout(() => {
water.classList.remove('pee');
urine.classList.remove('pee');
}, 1500)
}
}
function flush() {
isFlushing = true;
setTimeout(() => flushingAudio.play(), 300);
water.classList.add('flushing');
water.classList.remove('pee');
urine.classList.remove('pee');
}
water.addEventListener('click', pee);
water.addEventListener('animationend', () => {
water.classList.remove('flushing');
isFlushing = false;
})
flushBtn.addEventListener('click', flush);