-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript_main_page.js
More file actions
39 lines (31 loc) · 1001 Bytes
/
Copy pathscript_main_page.js
File metadata and controls
39 lines (31 loc) · 1001 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
33
34
35
36
37
38
39
document.addEventListener("DOMContentLoaded", () => {
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const h1Elements = document.querySelectorAll("h1");
h1Elements.forEach(h1Element => {
const textToAnimate = h1Element.dataset.value;
let interval = null;
h1Element.addEventListener("mouseover", () => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
h1Element.textContent = textToAnimate
.split("")
.map((letter, index) => {
if (index < iteration) {
return textToAnimate[index];
}
return letters[Math.floor(Math.random() * 26)];
})
.join("");
if (iteration >= textToAnimate.length) {
clearInterval(interval);
}
iteration += 1 / 3;
}, 25);
});
h1Element.addEventListener("mouseout", () => {
clearInterval(interval);
h1Element.textContent = textToAnimate;
});
});
});