-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (58 loc) · 1.83 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const starsTd = document.querySelectorAll('.star');
//getting a random star index:
function randomTd() {
const randomIndex = Math.floor(Math.random() * starsTd.length);
return randomIndex;
}
//removing the star animation:
let saveArray = [];
function starsDisappearing() {
for (let i = 0; i < saveArray.length; i += 1) {
starsTd[saveArray[i]].className = 'star';
}
saveArray = [];
}
//adding a animation to random stars and calling that function every 3s:
setInterval(function () {
for (let i = 0; i < 30; i += 1) {
const rIndex = randomTd();
starsTd[rIndex].classList.add('starsFlashing');
saveArray.push(rIndex);
starsTd[rIndex].addEventListener('animationend', starsDisappearing);
}
return saveArray;
}, 3000);
//reseting animations on click!
const resetButton = document.getElementById('reset-button');
const rocket = document.querySelector('.rocket-complete');
const earth = document.querySelector('.earth');
const sky = document.querySelector('.sky');
const planets = document.querySelector('.planet-main');
function resetAnimation(element) {
element.style.animation = 'none';
element.offsetHeight; /* trigger reflow */
element.style.animation = null;
}
resetButton.addEventListener('click', ()=> {
resetAnimation(rocket);
resetAnimation(earth);
resetAnimation(sky);
resetAnimation(planets);
resetButton.style.display = 'none';
})
let animationCount = 0;
rocket.addEventListener('animationend', ()=> {
console.log(animationCount);
animationCount += 1;
if (animationCount != 1) {
resetButton.style.display = 'block';
animationCount = 0;
console.log(animationCount);
}
console.log(animationCount);
})
//mandatory step
const articleDiv = document.querySelector('article');
articleDiv.addEventListener('click', function () {
articleDiv.style.animationPlayState = 'running';
});