-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (87 loc) · 3.13 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const cube = document.getElementById("rubiks-cube");
const aniBtn = document.getElementById("animate-btn");
cube.addEventListener("animationend", () => {
cube.classList.remove("rotate");
aniBtn.classList.remove("active");
cube.classList.remove("paused");
removeAni(iMessage, loveMessage, youMessage, creditsText);
runAni(iMessage, loveMessage, youMessage, creditsText);
});
aniBtn.addEventListener("click", () => {
if (aniBtn.classList.contains("active")) {
aniBtn.classList.remove("active");
cube.classList.add("paused");
pauseAni(iMessage, loveMessage, youMessage, creditsText);
hoverText.style.opacity = "1";
} else {
cube.classList.remove("paused");
aniBtn.classList.add("active");
cube.classList.add("rotate");
runAni(iMessage, loveMessage, youMessage, creditsText);
playAni(iMessage, loveMessage, youMessage, creditsText);
hoverText.style.opacity = "0";
}
});
const aniCount = document.querySelectorAll("#animation-count");
aniCount.forEach((btn) => {
btn.addEventListener("click", () => {
if (!btn.classList.contains("active")) {
aniCount.forEach((otherBtn) => {
otherBtn.classList.remove("active");
});
btn.classList.add("active");
cube.style.animationIterationCount = btn.value;
console.log(
`ANIMATION-ITERATION-COUNT: ${cube.style.animationIterationCount}`
);
cube.classList.add("rotate");
playAni(iMessage, loveMessage, youMessage, creditsText);
}
});
});
const container = document.getElementById("cube-container");
const hoverText = document.getElementById("hover-text");
container.addEventListener("mouseenter", () => {
if (!aniBtn.classList.contains("active")) {
cube.classList.add("rotate");
cube.classList.remove("paused");
playAni(iMessage, loveMessage, youMessage, creditsText);
runAni(iMessage, loveMessage, youMessage, creditsText);
hoverText.style.opacity = "0";
}
});
container.addEventListener("mouseleave", () => {
if (!aniBtn.classList.contains("active")) {
cube.classList.add("paused");
pauseAni(iMessage, loveMessage, youMessage, creditsText);
hoverText.style.opacity = "1";
}
});
const iMessage = document.getElementById("i-message");
const loveMessage = document.getElementById("love-message");
const youMessage = document.getElementById("you-message");
const creditsText = document.getElementById("credits-text");
function playAni(first, second, third, fourt) {
first.classList.add("i-play");
second.classList.add("love-play");
third.classList.add("you-play");
fourt.classList.add("credits-play");
}
function removeAni(first, second, third, fourt) {
first.classList.remove("i-play");
second.classList.remove("love-play");
third.classList.remove("you-play");
fourt.classList.remove("credits-play");
}
function pauseAni(first, second, third, fourt) {
first.classList.add("paused");
second.classList.add("paused");
third.classList.add("paused");
fourt.classList.add("paused");
}
function runAni(first, second, third, fourt) {
first.classList.remove("paused");
second.classList.remove("paused");
third.classList.remove("paused");
fourt.classList.remove("paused");
}