-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (60 loc) · 1.88 KB
/
main.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
// rotate characters on hover
(async function () {
const characters = "abcdefghijklmnopqrstuvwxyz!#$%&/()=?€@[]{}§";
const elements = Array.from(document.querySelectorAll(".rotate-characters"));
function rotateCharacters(event) {
const element = event.currentTarget;
if (!element.dataset.originalText) {
element.dataset.originalText = element.innerText;
}
if (element.__rotate_characters_tid) {
clearInterval(element.__rotate_characters_tid);
}
const originalText = element.dataset.originalText;
let count = -1;
element.__rotate_characters_tid = setTimeout(function func() {
element.innerText = element.innerText
.split("")
.map((letter, index) => {
if (index < count) {
return originalText[index];
}
return characters[Math.floor(Math.random() * characters.length)];
})
.join("");
count += 1 / 3;
if (count < originalText.length) {
setTimeout(func, 40);
}
}, 40);
}
elements.forEach((element) => {
element.addEventListener("mouseover", rotateCharacters);
});
})();
// scroll text rows
(async function () {
const characters = "01";
const element = document.querySelector(".scroll-rows");
function fillRows() {
const height = Number.parseInt(window.getComputedStyle(element).height, 10);
const maxRows = (height / (11 * 1.5)) * 0.7;
element.innerText = "";
for (let i = 0; i < maxRows; i++) {
const row = document.createElement("div");
row.innerText = "c"
.repeat(50)
.split("")
.map((c) => characters[Math.floor(Math.random() * characters.length)])
.join("");
element.appendChild(row);
}
}
fillRows();
window.addEventListener("resize", () => {
fillRows();
});
setInterval(() => {
element.appendChild(element.firstElementChild);
}, 120);
})();