-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (27 loc) · 1.2 KB
/
index.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
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
document.querySelector("h1").onmouseover = event => {
let iterations = 0;
const interval = setInterval(() => {
event.target.innerText = event.target.innerText.split("").map((letter, index) => {
if (index < iterations) {
return event.target.dataset.value1[index];
}
return letters[Math.floor(Math.random() * 26)];
}).join("");
if (iterations >= event.target.dataset.value1.length) clearInterval(interval);
iterations += 1 / 2;
}, 30);
event.target.onmouseout = () => { // Trigger animation reversal on mouseout
let iterations = 0;
const interval = setInterval(() => {
event.target.innerText = event.target.innerText.split("").map((letter, index) => {
if (index < iterations) {
return event.target.dataset.value2[index];
}
return letters[Math.floor(Math.random() * 26)];
}).join("");
if (iterations >= event.target.dataset.value2.length) clearInterval(interval);
iterations += 1 / 2;
}, 30);
};
}