-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (55 loc) · 1.89 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
const title = document.getElementById("title");
const subtitle = document.getElementById("subtitle");
const quote = document.getElementById("quote");
const colors = [
"#ff6663",
"#ffcc66",
"#66ff66",
"#66ffff",
"#6666ff",
"#ff66ff",
"#cc66ff",
"#ff66cc"
];
const randomColor = () => {
const index = Math.floor(Math.random() * colors.length);
return colors[index];
};
const changeColor = () => {
const color = randomColor();
title.style.color = color;
subtitle.style.color = color;
quote.style.color = color;
};
setInterval(changeColor, 2000);
const titleAnimation = () => {
const animation = document.createDocumentFragment();
const text = title.textContent.split("");
text.forEach((letter, index) => {
const span = document.createElement("span");
span.textContent = letter;
span.style.opacity = "0";
span.style.transition = `opacity 0.5s ${Math.random() * 2}s`;
span.style.transform = `translateY(${Math.random() * 50 - 25}px) rotate(${Math.random() * 360}deg)`;
animation.appendChild(span);
});
title.textContent = "";
title.appendChild(animation);
const letters = title.children;
for (let i = 0; i < letters.length; i++) {
setTimeout(() => {
letters[i].style.opacity = "1";
}, i * Math.random() * 1000);
}
};
setInterval(titleAnimation, 5000);
const randomizeElements = () => {
const elements = Array.from(document.body.children);
elements.forEach(element => {
const randomTransform = `translate(${Math.random() * 100 - 50}px, ${Math.random() * 100 - 50}px) rotate(${Math.random() * 360}deg)`;
const randomScale = Math.random() * 2;
element.style.transform = `${randomTransform} scale(${randomScale})`;
element.style.transition = `transform 0.5s ${Math.random() * 2}s`;
});
};
setInterval(randomizeElements, 3000);