-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimations.js
More file actions
387 lines (348 loc) · 11.1 KB
/
Copy pathanimations.js
File metadata and controls
387 lines (348 loc) · 11.1 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
// Initialize GSAP plugins
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);
// Wait for DOM to load
document.addEventListener('DOMContentLoaded', function() {
// 1. NAVBAR SLIDE-IN ANIMATION
const navbar = document.querySelector('.header');
const navLinks = document.querySelectorAll('.nav-links li');
const logo = document.querySelector('.logo');
// Initial state - navbar hidden
gsap.set(navbar, { y: -100, opacity: 0 });
gsap.set(navLinks, { y: -20, opacity: 0 });
gsap.set(logo, { x: -50, opacity: 0 });
// Navbar slide-in timeline
const navbarTimeline = gsap.timeline();
navbarTimeline
.to(navbar, {
y: 0,
opacity: 1,
duration: 0.8,
ease: "power2.out"
})
.to(logo, {
x: 0,
opacity: 1,
duration: 0.6,
ease: "back.out(1.7)"
}, "-=0.4")
.to(navLinks, {
y: 0,
opacity: 1,
duration: 0.5,
stagger: 0.1,
ease: "power2.out"
}, "-=0.3");
// 2. HERO SECTION ANIMATIONS
const heroElements = {
badge: document.querySelector('.hero-badge'),
titleLines: document.querySelectorAll('.title-line'),
description: document.querySelector('.hero-description'),
actions: document.querySelector('.hero-actions'),
features: document.querySelectorAll('.hero-features .feature'),
orb: document.querySelector('.dream-orb'),
stats: document.querySelectorAll('.stat')
};
// Hero timeline
const heroTimeline = gsap.timeline();
heroTimeline
.from(heroElements.badge, {
y: 30,
opacity: 0,
duration: 0.8,
ease: "power2.out"
})
.from(heroElements.titleLines, {
y: 50,
opacity: 0,
duration: 0.8,
stagger: 0.2,
ease: "power2.out"
}, "-=0.4")
.from(heroElements.description, {
y: 30,
opacity: 0,
duration: 0.8,
ease: "power2.out"
}, "-=0.4")
.from(heroElements.actions, {
y: 30,
opacity: 0,
duration: 0.8,
ease: "power2.out"
}, "-=0.4")
.from(heroElements.features, {
y: 30,
opacity: 0,
duration: 0.6,
stagger: 0.1,
ease: "power2.out"
}, "-=0.6")
.from(heroElements.orb, {
scale: 0,
rotation: 180,
opacity: 0,
duration: 1.2,
ease: "back.out(1.7)"
}, "-=0.8")
.from(heroElements.stats, {
y: 30,
opacity: 0,
duration: 0.6,
stagger: 0.1,
ease: "power2.out"
}, "-=0.6");
// 3. BUTTON HOVER PULSE ANIMATIONS
const allButtons = document.querySelectorAll('button, .cta-button');
allButtons.forEach(button => {
button.addEventListener('mouseenter', function() {
gsap.to(this, {
scale: 1.05,
duration: 0.3,
ease: "power2.out"
});
});
button.addEventListener('mouseleave', function() {
gsap.to(this, {
scale: 1,
duration: 0.3,
ease: "power2.out"
});
});
});
// 4. SCROLL-TRIGGERED ANIMATIONS
// Features Section
gsap.from('.section-header', {
scrollTrigger: {
trigger: '.features-section',
start: 'top 80%',
end: 'bottom 20%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 0.8,
ease: "power2.out"
});
gsap.from('.feature-card', {
scrollTrigger: {
trigger: '.features-grid',
start: 'top 80%',
end: 'bottom 20%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 0.8,
stagger: 0.2,
ease: "power2.out"
});
// Testimonials Section
gsap.from('.testimonials-section .section-header', {
scrollTrigger: {
trigger: '.testimonials-section',
start: 'top 80%',
end: 'bottom 20%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 0.8,
ease: "power2.out"
});
gsap.from('.testimonial-card', {
scrollTrigger: {
trigger: '.testimonials-grid',
start: 'top 80%',
end: 'bottom 20%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 0.8,
stagger: 0.2,
ease: "power2.out"
});
// CTA Section
gsap.from('.cta-content', {
scrollTrigger: {
trigger: '.cta-section',
start: 'top 80%',
end: 'bottom 20%',
toggleActions: 'play none none reverse'
},
y: 50,
opacity: 0,
duration: 0.8,
ease: "power2.out"
});
// 5. ENHANCED ORB ANIMATIONS
const orb = document.querySelector('.dream-orb');
const floatingElements = document.querySelectorAll('.element');
const rings = document.querySelectorAll('.ring');
const energyLines = document.querySelectorAll('.energy-line');
// Continuous orb rotation
gsap.to(orb, {
rotation: 360,
duration: 60,
ease: "none",
repeat: -1
});
// Floating elements enhanced animation
floatingElements.forEach((element, index) => {
gsap.to(element, {
y: -20,
rotation: 5,
duration: 3 + index * 0.5,
ease: "power1.inOut",
repeat: -1,
yoyo: true
});
});
// Energy lines animation
energyLines.forEach((line, index) => {
gsap.to(line, {
scaleY: 1.5,
opacity: 0.8,
duration: 2,
ease: "power2.inOut",
repeat: -1,
yoyo: true,
delay: index * 0.5
});
});
// 6. PARALLAX EFFECTS
gsap.to('.hero-section::before', {
scrollTrigger: {
trigger: '.hero-section',
start: 'top bottom',
end: 'bottom top',
scrub: 1
},
y: -100,
ease: "none"
});
// 7. STATS COUNTER ANIMATION
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach(stat => {
const finalValue = stat.textContent;
const isPercentage = finalValue.includes('%');
const isPlus = finalValue.includes('+');
const numericValue = parseFloat(finalValue.replace(/[^\d.]/g, ''));
gsap.fromTo(stat,
{ textContent: 0 },
{
scrollTrigger: {
trigger: '.stats',
start: 'top 80%',
toggleActions: 'play none none reverse'
},
textContent: numericValue,
duration: 2,
ease: "power2.out",
snap: { textContent: 1 },
onUpdate: function() {
const currentValue = Math.round(this.targets()[0].textContent);
if (isPercentage) {
stat.textContent = currentValue + '%';
} else if (isPlus) {
stat.textContent = currentValue + '+';
} else {
stat.textContent = currentValue;
}
}
}
);
});
// 8. SMOOTH SCROLLING FOR NAVIGATION
const navLinks = document.querySelectorAll('.nav-links a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
gsap.to(window, {
duration: 1.5,
scrollTo: {
y: targetSection,
offsetY: 80
},
ease: "power2.inOut"
});
}
});
});
// 9. INTERACTIVE HOVER EFFECTS
const featureCards = document.querySelectorAll('.feature-card');
featureCards.forEach(card => {
card.addEventListener('mouseenter', function() {
gsap.to(this, {
scale: 1.02,
duration: 0.3,
ease: "power2.out"
});
});
card.addEventListener('mouseleave', function() {
gsap.to(this, {
scale: 1,
duration: 0.3,
ease: "power2.out"
});
});
});
// 10. LOADING SEQUENCE
// Add a subtle loading animation for the entire page
gsap.from('body', {
opacity: 0,
duration: 1,
ease: "power2.out"
});
// 11. RESPONSIVE ANIMATIONS
// Adjust animations for mobile devices
function checkMobile() {
if (window.innerWidth <= 768) {
// Reduce stagger timing on mobile
gsap.set('.feature-card', { stagger: 0.1 });
gsap.set('.testimonial-card', { stagger: 0.1 });
}
}
checkMobile();
window.addEventListener('resize', checkMobile);
// 12. PERFORMANCE OPTIMIZATION
// Pause animations when tab is not visible
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
gsap.globalTimeline.pause();
} else {
gsap.globalTimeline.resume();
}
});
// 13. ACCESSIBILITY CONSIDERATIONS
// Respect user's motion preferences
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
gsap.globalTimeline.timeScale(0.5);
}
// 14. ERROR HANDLING
// Graceful fallback if GSAP fails to load
if (typeof gsap === 'undefined') {
console.warn('GSAP not loaded, falling back to CSS animations');
document.body.classList.add('gsap-fallback');
}
});
// 15. UTILITY FUNCTIONS
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Optimize scroll performance
const optimizedScrollHandler = debounce(() => {
// Any scroll-based calculations can go here
}, 16);
window.addEventListener('scroll', optimizedScrollHandler);