-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (25 loc) · 966 Bytes
/
Copy pathindex.js
File metadata and controls
36 lines (25 loc) · 966 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
const chars = "abcdefghiklmnopqrstuvwxyz0123456789"
const randomChar = () => {
const randomIndex = Math.floor(Math.random() * chars.length);
return chars[randomIndex];
}
const randomString = () => {
let string = "";
for (let i = 0; i < 10000; i++) {
string += randomChar();
}
return string;
}
const box = document.getElementsByClassName("text-container")[0]
box.innerHTML = randomString();
document.getElementsByClassName("body-container")[0].onmousemove = (e) => {
box.innerHTML = randomString();
let x = e.clientX - e.target.offsetLeft;
let y = e.clientY - e.target.offsetTop;
box.style.setProperty("--x", `${x}px`);
box.style.setProperty("--y", `${y}px`);
x = (e.clientX - e.target.offsetLeft) / box.offsetWidth - 0.5;
y = (e.clientY - e.target.offsetTop) / box.offsetHeight - 0.5;
box.style.setProperty("--TiltX", `${x * 20}deg`);
box.style.setProperty("--TiltY", `${y * 20}deg`);
}