-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (142 loc) · 5.32 KB
/
script.js
File metadata and controls
159 lines (142 loc) · 5.32 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
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
document.addEventListener('DOMContentLoaded', () => {
// --- HERO CANVAS ANIMATION ---
const canvas = document.getElementById('hero-canvas');
if (canvas) {
const ctx = canvas.getContext('2d');
let particlesArray;
const setCanvasSize = () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
};
class Particle {
constructor(x, y, directionX, directionY, size, color) {
this.x = x;
this.y = y;
this.directionX = directionX;
this.directionY = directionY;
this.size = size;
this.color = color;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
ctx.fillStyle = 'rgba(0, 123, 255, 0.5)';
ctx.fill();
}
update() {
if (this.x > canvas.width || this.x < 0) {
this.directionX = -this.directionX;
}
if (this.y > canvas.height || this.y < 0) {
this.directionY = -this.directionY;
}
this.x += this.directionX;
this.y += this.directionY;
this.draw();
}
}
const init = () => {
particlesArray = [];
let numberOfParticles = (canvas.height * canvas.width) / 9000;
for (let i = 0; i < numberOfParticles; i++) {
let size = (Math.random() * 2) + 1;
let x = (Math.random() * ((innerWidth - size * 2) - (size * 2)) + size * 2);
let y = (Math.random() * ((innerHeight - size * 2) - (size * 2)) + size * 2);
let directionX = (Math.random() * .4) - .2;
let directionY = (Math.random() * .4) - .2;
let color = '#007BFF';
particlesArray.push(new Particle(x, y, directionX, directionY, size, color));
}
};
const connect = () => {
let opacityValue = 1;
for (let a = 0; a < particlesArray.length; a++) {
for (let b = a; b < particlesArray.length; b++) {
let distance = ((particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x)) +
((particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y));
if (distance < (canvas.width / 7) * (canvas.height / 7)) {
opacityValue = 1 - (distance / 20000);
ctx.strokeStyle = `rgba(0, 123, 255, ${opacityValue})`;
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(particlesArray[a].x, particlesArray[b].x);
ctx.lineTo(particlesArray[b].x, particlesArray[b].y);
ctx.stroke();
}
}
}
};
const animate = () => {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, innerWidth, innerHeight);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
}
connect();
};
window.addEventListener('resize', () => {
setCanvasSize();
init();
});
setCanvasSize();
init();
animate();
}
// Simple hero content fade in
gsap.to('.hero-content', {
opacity: 1,
y: 0,
duration: 1.5,
ease: 'power2.out',
delay: 0.5
});
// --- SECTION FADE-IN ANIMATIONS ON SCROLL ---
const animateOnScroll = (selector, stagger = 0.1) => {
gsap.utils.toArray(selector).forEach(elem => {
gsap.to(elem, {
opacity: 1,
y: 0,
duration: 0.8,
stagger: stagger,
scrollTrigger: {
trigger: elem,
start: 'top 85%',
end: 'bottom 20%',
toggleActions: 'play none none none',
}
});
});
};
animateOnScroll('.car-card', 0.2);
animateOnScroll('.feature-item', 0.2);
animateOnScroll('.testimonial-card', 0.2);
animateOnScroll('.footer-col', 0.2);
gsap.utils.toArray('.section-title').forEach(title => {
gsap.from(title, {
opacity: 0,
y: 30,
duration: 0.8,
scrollTrigger: {
trigger: title,
start: 'top 90%',
toggleActions: 'play none none none',
}
});
});
// Smooth scroll for nav links
document.querySelectorAll('.nav-link').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if(targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});