-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
241 lines (211 loc) · 7.59 KB
/
Copy pathscript.js
File metadata and controls
241 lines (211 loc) · 7.59 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// script.js
// Lenis Smooth Scroll
const lenis = new Lenis({
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
direction: 'vertical',
smooth: true,
});
function raf(time) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
// Sync GSAP with Lenis
gsap.registerPlugin(ScrollTrigger);
lenis.on('scroll', ScrollTrigger.update);
gsap.ticker.add((time) => { lenis.raf(time * 1000); });
gsap.ticker.lagSmoothing(0);
// Loader & WebGL Init
window.addEventListener('load', () => {
initWebGL();
const tl = gsap.timeline();
tl.to('.loader-text', { opacity: 0, duration: 0.5, delay: 0.5 })
.to('.loader', { height: 0, duration: 1, ease: 'power4.inOut' })
.to('#gl', { opacity: 1, duration: 2 }, '-=0.5')
.to('.fade-in', { y: 0, opacity: 1, duration: 1, stagger: 0.2, ease: 'power3.out' }, '-=1')
.fromTo('.anim-word', { y: '110%' }, { y: '0%', duration: 1.2, stagger: 0.1, ease: 'power4.out' }, '-=1.2')
.to('.hero-img-wrapper', { scale: 1, rotateY: 0, duration: 1.5, ease: 'expo.out' }, '-=1.2')
.to('.scroll-down-tracker', { opacity: 1, duration: 1 }, '-=0.5');
});
// Three.js Abstract Flowing Object
function initWebGL() {
const canvas = document.getElementById('gl');
if (!canvas) return;
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xECF4E8, 5, 20);
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 0, 12);
scene.add(new THREE.AmbientLight(0xffffff, 2.5));
const l1 = new THREE.DirectionalLight(0xffffff, 1.5); l1.position.set(5, 10, 5); scene.add(l1);
const l2 = new THREE.PointLight(0xCBF3BB, 3, 30); l2.position.set(-8, 5, 2); scene.add(l2);
const group = new THREE.Group();
scene.add(group);
const geo = new THREE.TorusKnotGeometry(3, 0.8, 200, 32);
const mat = new THREE.MeshPhysicalMaterial({
color: 0x93BFC7,
roughness: 0.1,
metalness: 0.1,
transmission: 0.9,
thickness: 1.5,
wireframe: true,
transparent: true,
opacity: 0.15
});
const mesh = new THREE.Mesh(geo, mat);
group.add(mesh);
const geo2 = new THREE.IcosahedronGeometry(2, 4);
const mat2 = new THREE.MeshPhysicalMaterial({ color: 0x1A2F24, wireframe: true, transparent: true, opacity: 0.08 });
const mesh2 = new THREE.Mesh(geo2, mat2);
group.add(mesh2);
let mouseX = 0, mouseY = 0;
window.addEventListener('mousemove', e => {
mouseX = (e.clientX / innerWidth - 0.5) * 2;
mouseY = -(e.clientY / innerHeight - 0.5) * 2;
});
window.addEventListener('resize', () => {
renderer.setSize(innerWidth, innerHeight);
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
});
function animate() {
requestAnimationFrame(animate);
mesh.rotation.y += 0.001;
mesh.rotation.x += 0.002;
mesh2.rotation.y -= 0.002;
mesh2.rotation.z -= 0.001;
group.rotation.x += (mouseY * 0.1 - group.rotation.x) * 0.05;
group.rotation.y += (mouseX * 0.1 - group.rotation.y) * 0.05;
camera.position.x += (mouseX * 0.5 - camera.position.x) * 0.05;
camera.position.y += (-mouseY * 0.5 - camera.position.y) * 0.05;
camera.lookAt(scene.position);
renderer.render(scene, camera);
}
animate();
}
// Custom Cursor
const cr = document.getElementById('c-ring'), cd = document.getElementById('c-dot');
let mx = innerWidth / 2, my = innerHeight / 2, ox = mx, oy = my;
window.addEventListener('mousemove', e => {
mx = e.clientX; my = e.clientY;
cd.style.transform = `translate(${mx}px, ${my}px)`;
});
gsap.ticker.add(() => {
ox += (mx - ox) * 0.15; oy += (my - oy) * 0.15;
cr.style.transform = `translate(${ox}px, ${oy}px)`;
});
document.querySelectorAll('a, button, .card-inner, .s-link, .marquee-content img, .download-link').forEach(el => {
el.addEventListener('mouseenter', () => document.body.classList.add('hov'));
el.addEventListener('mouseleave', () => document.body.classList.remove('hov'));
});
// Split Text manually for About Section
const aboutText = document.querySelector('.about-text');
if (aboutText) {
const words = aboutText.innerText.split(' ');
aboutText.innerHTML = '';
words.forEach(word => {
const span = document.createElement('span');
span.className = 'word';
span.innerText = word + ' ';
aboutText.appendChild(span);
});
}
// Reveal About
ScrollTrigger.create({
trigger: '#about',
start: 'top 65%',
onEnter: () => {
gsap.to('.word', { opacity: 1, duration: 0.05, stagger: 0.03, ease: 'none' });
gsap.to('.fade-up', { y: 0, opacity: 1, duration: 1, stagger: 0.1, ease: 'power3.out', delay: 0.4 });
}
});
// Sticky Cards Parallax & Scaling
const cards = document.querySelectorAll('.card-sticky');
cards.forEach((card, index) => {
const img = card.querySelector('.card-img');
if(img) {
gsap.to(img, {
y: "15%",
ease: 'none',
scrollTrigger: { trigger: card, start: 'top bottom', end: 'bottom top', scrub: true }
});
}
if (index < cards.length - 1 && window.innerWidth > 900) {
gsap.to(card.querySelector('.card-inner'), {
scale: 0.94,
opacity: 0.4,
ease: 'none',
scrollTrigger: {
trigger: cards[index + 1],
start: 'top 85%',
end: 'top 15%',
scrub: true
}
});
}
});
// Reveal Contact Form
ScrollTrigger.create({
trigger: '#contact',
start: 'top 75%',
onEnter: () => {
gsap.to('.c-form', { y: 0, opacity: 1, duration: 1, ease: 'power3.out' });
}
});
// Mobile Menu Toggle
const menuToggle = document.querySelector('.menu-toggle');
const mobileMenuOverlay = document.querySelector('.mobile-menu-overlay');
const navMain = document.querySelector('.nav-main');
const mobileLinks = document.querySelectorAll('.mobile-link');
if (menuToggle) {
menuToggle.addEventListener('click', () => {
menuToggle.classList.toggle('active');
mobileMenuOverlay.classList.toggle('open');
navMain.classList.toggle('menu-open');
if (mobileMenuOverlay.classList.contains('open')) {
lenis.stop();
} else {
lenis.start();
}
});
mobileLinks.forEach(link => {
link.addEventListener('click', () => {
menuToggle.classList.remove('active');
mobileMenuOverlay.classList.remove('open');
navMain.classList.remove('menu-open');
lenis.start();
});
});
}
// Contact Form Submit Handling
const contactForm = document.getElementById('cf');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const r = document.getElementById('form-resp');
const n = document.querySelector('input[name="name"]').value;
if(r) { r.style.display = 'block'; r.style.color = 'var(--ink2)'; r.textContent = 'Sending...'; }
fetch("https://formsubmit.co/ajax/dasayush.0601@gmail.com", {
method: "POST",
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
body: JSON.stringify({
name: n,
email: document.querySelector('input[name="email"]').value,
message: document.querySelector('textarea[name="message"]').value,
_captcha: false
})
})
.then(response => response.json())
.then(data => {
if(r) { r.style.color = '#4ade80'; r.style.marginTop = '1rem'; r.textContent = `Message sent — I'll be in touch, ${n}.`; }
contactForm.reset();
})
.catch(error => {
if(r) { r.style.color = '#f87171'; r.textContent = 'Error sending message. Please try again.'; }
console.log(error);
});
});
}