-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (37 loc) · 1.27 KB
/
script.js
File metadata and controls
46 lines (37 loc) · 1.27 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
let value1 = document.getElementById('value1');
let value2 = document.getElementById('value2');
let value3 = document.getElementById('value3');
let btnSpin = document.getElementById('btnSpin');
let values = [
'😃', '😎', '😇', '🤣', '🤩', '😮', '🤑', '💀', '😴'
];
function getRandomValue() {
return values[Math.floor(Math.random() * 9)];
}
let animationId;
function updateAnimation(newSpeed) {
if (animationId) clearInterval(animationId);
document.documentElement.style.setProperty('--speed', newSpeed);
animationId = setInterval(() => {
value1.innerText = getRandomValue();
value2.innerText = getRandomValue();
value3.innerText = getRandomValue();
}, 1000/newSpeed);
}
btnSpin.onclick = function () {
if(this.innerHTML === 'STOP') {
this.innerHTML = 'SPIN';
clearInterval(animationId);
value1.classList.remove('animate');
value2.classList.remove('animate');
value3.classList.remove('animate');
btnSpin.classList.remove('stop');
} else {
this.innerHTML = 'STOP';
updateAnimation(5);
value1.classList.add('animate');
value2.classList.add('animate');
value3.classList.add('animate');
btnSpin.classList.add('stop');
}
}