-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.js
More file actions
32 lines (27 loc) · 1018 Bytes
/
animation.js
File metadata and controls
32 lines (27 loc) · 1018 Bytes
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
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*[].,-=;|'";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
event.target.classList.remove("gray");
event.target.classList.add("white");
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((_letter, index) => {
if (index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * letters.length)]
})
.join("");
if (iteration >= event.target.dataset.value.length) {
clearInterval(interval);
setTimeout(() => {
event.target.classList.remove("white");
event.target.classList.add("gray");
}, 500);
}
iteration += 1 / event.target.dataset.value.length;
}, 30);
}