-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
124 lines (94 loc) · 3.19 KB
/
Copy pathscript.js
File metadata and controls
124 lines (94 loc) · 3.19 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function toggleMenu() {
const menu = document.querySelector(".menu-links");
const icon = document.querySelector(".hamburger-icon");
menu.classList.toggle("open");
icon.classList.toggle("open");
}
document.addEventListener('DOMContentLoaded', function() {
const title = document.querySelector('.title');
title.classList.add('typing');
title.addEventListener('animationend', function() {
title.style.borderRight = 'none';
title.classList.remove('typing');
});
});
function displayPopup() {
document.getElementById('popup').style.display = 'block';
}
function hidePopup() {
document.getElementById('popup').style.display = 'none';
}
function createParticles() {
const numParticles = 22;
const particleContainer = document.querySelector('.particle-container');
for (let i = 0; i < numParticles; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
particle.style.left = `${getRandomNumber(0, window.innerWidth)}px`;
particle.style.top = `${getRandomNumber(-500, -50)}px`;
particleContainer.appendChild(particle);
animateParticle(particle);
}
}
function animateParticle(particle) {
const duration = Math.random() * 5 + 2;
particle.style.animationDuration = `${duration}s`;
particle.style.animationDelay = `${Math.random() * 5}s`;
}
function getRandomNumber(min, max) {
return Math.random() * (max - min) + min;
}
window.addEventListener('load', () => {
createParticles();
const animationDuration = 8000;
const particles = document.querySelectorAll('.particle');
const delayBetweenRemovals = animationDuration / particles.length;
function removeParticleWithDelay(index) {
if (index < particles.length) {
setTimeout(() => {
particles[index].remove();
removeParticleWithDelay(index + 1);
}, delayBetweenRemovals);
}
}
setTimeout(() => {
removeParticleWithDelay(0);
}, animationDuration);
});
const cursor = document.querySelector('.cursor');
function moveCursor(event) {
const cursorSize = 12;
cursor.style.left = `${event.clientX - cursorSize / 2}px`;
cursor.style.top = `${event.clientY - cursorSize / 2}px`;
}
function updateCursorOnScroll() {
const cursorSize = 12;
cursor.style.top = `${window.scrollY + event.clientY - cursorSize / 2}px`;
}
window.addEventListener('mousemove', moveCursor);
window.addEventListener('scroll', updateCursorOnScroll);
// Function to handle gyroscope change
function handleGyroscope(event) {
const beta = event.beta;
const particles = document.querySelectorAll('.particle');
particles.forEach(particle => {
particle.style.transform = `translateY(${beta}deg)`;
});
}
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', handleGyroscope);
} else {
console.log('Device does not support gyroscope.');
}
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
function removeCursorOnMobile() {
const cursor = document.querySelector('.cursor');
if (isMobileDevice()) {
cursor.style.display = 'none';
}
}
document.addEventListener('DOMContentLoaded', function() {
removeCursorOnMobile();
});