-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
75 lines (45 loc) · 1.52 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
let index = 0,
interval = 1000;
const rand = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
const animate = star => {
star.style.setProperty("--star-left", `${rand(-10, 100)}%`);
star.style.setProperty("--star-top", `${rand(-40, 80)}%`);
star.style.animation = "none";
star.offsetHeight;
star.style.animation = "";
}
const trailer = document.getElementById("trailer");
window.onmousemove = e => {
const x = e.clientX - trailer.offsetWidth / 2,
y = e.clientY - trailer.offsetHeight / 2;
const keyframes = {
transform: `translate(${x}px, ${y}px)`
}
trailer.animate(keyframes, {
duration: 800,
fill: "forwards"
})
}
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval_a = null;
document.addEventListener("DOMContentLoaded", event => {
let iteration = 0;
const h1 = document.querySelector("h1");
clearInterval(interval_a);
interval_a = setInterval(() => {
h1.querySelector(".magic").innerText = h1.querySelector(".magic").innerText
.split("")
.map((letter, index) => {
if (index < iteration) {
return h1.querySelector(".magic").dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if (iteration >= h1.querySelector(".magic").dataset.value.length) {
clearInterval(interval_a);
}
iteration += 1 / 3;
}, 30);
});