-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (134 loc) · 4.44 KB
/
script.js
File metadata and controls
155 lines (134 loc) · 4.44 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
document.addEventListener("DOMContentLoaded", function () {
// --- 1. Cursive Write-on Animation ---
const nameSvg = document.getElementById("name-svg");
if (sessionStorage.getItem("animationPlayed") === null) {
setTimeout(() => {
nameSvg.classList.add("visible");
nameSvg.classList.add("animate");
sessionStorage.setItem("animationPlayed", "true");
}, 500); // Small delay to prevent animation from firing on browser refresh
} else {
nameSvg.classList.add("visible");
// Set final state directly if animation has already played
nameSvg.querySelectorAll(".name-text").forEach((text) => {
text.style.strokeDashoffset = 0;
text.style.fill = text.classList.contains("shekhawat-color")
? "#22d3ee"
: "#e5e7eb";
});
}
// --- 2. Geometric Background Animation ---
const canvas = document.getElementById("geometric-background");
const ctx = canvas.getContext("2d");
let particles = [];
const particleCount = 70;
function setCanvasSize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
function createParticles() {
particles = [];
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
radius: Math.random() * 1.5 + 1,
});
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update particle positions
particles.forEach((p) => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
ctx.fillStyle = "rgba(34, 211, 238, 0.5)";
ctx.fill();
});
// Draw lines between nearby particles
ctx.beginPath();
for (let i = 0; i < particles.length; i++) {
for (let j = i; j < particles.length; j++) {
const dist = Math.sqrt(
(particles[i].x - particles[j].x) ** 2 +
(particles[i].y - particles[j].y) ** 2
);
if (dist < 120) {
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
}
}
}
ctx.lineWidth = 0.5;
ctx.strokeStyle = "rgba(34, 211, 238, 0.15)";
ctx.stroke();
requestAnimationFrame(draw);
}
setCanvasSize();
createParticles();
draw();
window.addEventListener("resize", () => {
setCanvasSize();
createParticles(); // Recreate particles for new screen size
});
// --- 3. Scroll-triggered Animations ---
const animatedElements = document.querySelectorAll(".animate-on-scroll");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const delay = entry.target.dataset.delay || 0;
setTimeout(() => {
entry.target.classList.add("is-visible");
}, delay * 1000);
observer.unobserve(entry.target); // Animate only once
}
});
},
{
threshold: 0.1,
}
);
animatedElements.forEach((el) => {
observer.observe(el);
});
// --- Existing Functionality ---
// Custom Cursor Logic
const cursorDot = document.querySelector(".custom-cursor-dot");
const cursorOutline = document.querySelector(".custom-cursor-outline");
window.addEventListener("mousemove", function (e) {
const posX = e.clientX;
const posY = e.clientY;
cursorDot.style.left = `${posX}px`;
cursorDot.style.top = `${posY}px`;
cursorOutline.animate(
{
left: `${posX}px`,
top: `${posY}px`,
},
{
duration: 500,
fill: "forwards",
}
);
});
// Mobile Menu Toggle
const mobileMenuButton = document.getElementById("mobile-menu-button");
const mobileMenu = document.getElementById("mobile-menu");
mobileMenuButton.addEventListener("click", function () {
mobileMenu.classList.toggle("hidden");
});
// Close mobile menu when a link is clicked
const mobileMenuLinks = mobileMenu.querySelectorAll("a");
mobileMenuLinks.forEach((link) => {
link.addEventListener("click", () => {
mobileMenu.classList.add("hidden");
});
});
});