-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (69 loc) · 2.35 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
72
73
74
75
76
77
78
79
src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js">
WebFont.load({
google: {
families: ["Borel"]
}
});
WebFont.load({
google: {
families: ["Roboto Condensed"]
}
});
document.addEventListener("mousemove", function(event) {
var cursor = document.querySelector(".cursor");
cursor.style.left = event.clientX + "px";
cursor.style.top = event.clientY + "px";
});
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= event.target.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 58);
}
const starsContainer = document.querySelector('.stars');
const numStars = 100;
for (let i = 0; i < numStars; i++) {
const star = document.createElement('div');
star.classList.add('star');
star.style.top = `${Math.random() * 100}%`;
star.style.left = `${Math.random() * 100}%`;
star.style.animationDelay = `${Math.random() * 2}s`;
starsContainer.appendChild(star);
}
setTimeout(() => {
starsContainer.classList.add('fade-in');
}, 1000);
document.addEventListener('mousemove', e => {
const x = e.clientX / window.innerWidth;
const y = e.clientY / window.innerHeight;
starsContainer.style.transform = `translate(-${x * 50}px, -${y * 50}px)`;
});
const background = document.querySelector('.background');
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
background.classList.remove('day');
background.classList.add('night');
} else {
background.classList.remove('night');
background.classList.add('day');
}
const backgrounds = ['images/bg1.webp', 'images/bg2.webp', 'images/bg3.webp', 'images/bg4.webp', 'images/bg5.webp', 'images/bg6.webp'];
const randomIndex = Math.floor(Math.random() * backgrounds.length);
const backgroundElement = document.querySelector('.day');
if (backgroundElement) {
backgroundElement.style.backgroundImage = `url(${backgrounds[randomIndex]})`;
}