-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (131 loc) · 4.89 KB
/
script.js
File metadata and controls
159 lines (131 loc) · 4.89 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
// Interactive Stars System
const starsContainer = document.getElementById('stars');
const heroSection = document.getElementById('hero');
if (starsContainer && heroSection) {
const stars = [];
const numStars = 100;
// Create stars
for (let i = 0; i < numStars; i++) {
const star = document.createElement('div');
star.className = 'star';
const x = Math.random() * 100;
const y = Math.random() * 100;
const size = Math.random() * 2 + 1;
star.style.left = x + '%';
star.style.top = y + '%';
star.style.width = size + 'px';
star.style.height = size + 'px';
star.style.opacity = Math.random() * 0.5 + 0.3;
star.dataset.x = x;
star.dataset.y = x;
starsContainer.appendChild(star);
stars.push(star);
}
// Mouse interaction with stars
let mouseX = 0;
let mouseY = 0;
heroSection.addEventListener('mousemove', (e) => {
const rect = heroSection.getBoundingClientRect();
mouseX = ((e.clientX - rect.left) / rect.width) * 100;
mouseY = ((e.clientY - rect.top) / rect.height) * 100;
stars.forEach(star => {
const starX = parseFloat(star.dataset.x);
const starY = parseFloat(star.dataset.y);
const dx = mouseX - starX;
const dy = mouseY - starY;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 15) {
const force = (15 - distance) / 15;
const moveX = -dx * force * 2;
const moveY = -dy * force * 2;
star.style.transform = `translate(${moveX}px, ${moveY}px) scale(${1 + force * 0.5})`;
star.style.opacity = Math.min(1, 0.5 + force * 0.5);
} else if (distance < 25) {
const force = (25 - distance) / 25;
const moveX = -dx * force * 0.5;
const moveY = -dy * force * 0.5;
star.style.transform = `translate(${moveX}px, ${moveY}px)`;
} else {
star.style.transform = 'translate(0, 0) scale(1)';
}
});
});
heroSection.addEventListener('mouseleave', () => {
stars.forEach(star => {
star.style.transform = 'translate(0, 0) scale(1)';
star.style.opacity = Math.random() * 0.5 + 0.3;
});
});
}
// Custom Cursor
const cursor = document.querySelector('.cursor');
const cursorFollower = document.querySelector('.cursor-follower');
if (cursor && cursorFollower) {
let cursorX = 0, cursorY = 0;
let followerX = 0, followerY = 0;
document.addEventListener('mousemove', (e) => {
cursorX = e.clientX;
cursorY = e.clientY;
cursor.style.left = cursorX + 'px';
cursor.style.top = cursorY + 'px';
});
// Smooth follower animation
function animateFollower() {
const dx = cursorX - followerX;
const dy = cursorY - followerY;
followerX += dx * 0.15;
followerY += dy * 0.15;
cursorFollower.style.left = followerX + 'px';
cursorFollower.style.top = followerY + 'px';
requestAnimationFrame(animateFollower);
}
animateFollower();
// Hover effect on interactive elements
const hoverElements = document.querySelectorAll('a, button, .cta-button, .contact-card, .about-card, .team-card');
hoverElements.forEach(element => {
element.addEventListener('mouseenter', () => {
cursor.classList.add('hover');
});
element.addEventListener('mouseleave', () => {
cursor.classList.remove('hover');
});
});
// Hide cursor on mobile
if ('ontouchstart' in window) {
cursor.style.display = 'none';
cursorFollower.style.display = 'none';
}
}
// Optimized Scroll Animations with Intersection Observer
const observerOptions = {
threshold: 0.15,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe all sections
document.querySelectorAll('.section').forEach(section => {
observer.observe(section);
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href !== '#') {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
});