-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
279 lines (231 loc) · 8.36 KB
/
script.js
File metadata and controls
279 lines (231 loc) · 8.36 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
// Navigation Toggle
const navToggle = document.getElementById('nav-toggle');
const navMenu = document.getElementById('nav-menu');
if (navToggle && navMenu) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
navToggle.classList.toggle('active');
});
}
// Close mobile menu when clicking on a nav link
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
if (navMenu && navToggle) {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}
// Update active link
navLinks.forEach(l => l.classList.remove('active'));
link.classList.add('active');
});
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Header background on scroll
window.addEventListener('scroll', () => {
const header = document.querySelector('.header');
if (window.scrollY > 100) {
header.style.background = 'rgba(26, 26, 26, 0.98)';
} else {
header.style.background = 'rgba(26, 26, 26, 0.95)';
}
});
// Animate numbers on scroll
const animateNumbers = () => {
const statNumbers = document.querySelectorAll('.stat-number');
if (statNumbers.length === 0) return;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const finalNumber = parseInt(target.textContent);
animateCounter(target, finalNumber);
observer.unobserve(target);
}
});
});
statNumbers.forEach(number => observer.observe(number));
};
const animateCounter = (element, target) => {
let current = 0;
const increment = target / 50;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
element.textContent = target + (element.textContent.includes('+') ? '+' : '');
clearInterval(timer);
} else {
element.textContent = Math.floor(current) + (element.textContent.includes('+') ? '+' : '');
}
}, 30);
};
// Service card click handlers
const serviceCards = document.querySelectorAll('.service-card');
serviceCards.forEach(card => {
card.addEventListener('click', () => {
const serviceName = card.querySelector('.service-title').textContent;
console.log(`Clicked on: ${serviceName}`);
// Add ripple effect
const ripple = document.createElement('div');
ripple.classList.add('ripple');
card.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
// You can add navigation logic here
// For example: window.location.href = `/services/${serviceName.toLowerCase().replace(/\s+/g, '-')}`;
});
// Add hover sound effect (optional)
card.addEventListener('mouseenter', () => {
// You can add a subtle sound effect here if desired
});
});
// Scroll reveal animation
const revealElements = () => {
const elements = document.querySelectorAll('.stat-card, .service-card, .client-logo');
if (elements.length === 0) return;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
elements.forEach(element => observer.observe(element));
};
// Social media link handlers
const socialLinks = document.querySelectorAll('.social-icon, .social-link');
socialLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const platform = link.querySelector('i').className;
console.log(`Opening ${platform} profile`);
// Add your actual social media URLs here
let url = '#';
if (platform.includes('linkedin')) {
url = 'https://linkedin.com/in/jamesadams';
} else if (platform.includes('github')) {
url = 'https://github.com/jamesadams';
} else if (platform.includes('instagram')) {
url = 'https://instagram.com/jamesadams';
} else if (platform.includes('twitter')) {
url = 'https://twitter.com/jamesadams';
} else if (platform.includes('facebook')) {
url = 'https://facebook.com/jamesadams';
} else if (platform.includes('pinterest')) {
url = 'https://pinterest.com/jamesadams';
} else if (platform.includes('behance')) {
url = 'https://behance.net/jamesadams';
}
if (url !== '#') {
window.open(url, '_blank');
}
});
});
// Initialize animations
document.addEventListener('DOMContentLoaded', () => {
animateNumbers();
revealElements();
// Add loading animation
document.body.style.opacity = '0';
document.body.style.transition = 'opacity 0.5s ease';
setTimeout(() => {
document.body.style.opacity = '1';
}, 100);
});
// Keyboard navigation support
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
if (navMenu && navToggle) {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}
}
});
// Resize handler for responsive adjustments
window.addEventListener('resize', () => {
if (window.innerWidth > 768 && navMenu && navToggle) {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}
});
// Custom cursor effect for service cards (optional enhancement)
const createCustomCursor = () => {
const cursor = document.createElement('div');
cursor.classList.add('custom-cursor');
document.body.appendChild(cursor);
document.addEventListener('mousemove', (e) => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
});
serviceCards.forEach(card => {
card.addEventListener('mouseenter', () => {
cursor.style.transform = 'scale(1.5)';
cursor.style.background = '#ffd700';
});
card.addEventListener('mouseleave', () => {
cursor.style.transform = 'scale(1)';
cursor.style.background = 'rgba(255, 255, 255, 0.5)';
});
});
};
// Performance optimization: debounce scroll events
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
const debouncedScrollHandler = debounce(() => {
const header = document.querySelector('.header');
if (window.scrollY > 100) {
header.style.background = 'rgba(26, 26, 26, 0.98)';
} else {
header.style.background = 'rgba(26, 26, 26, 0.95)';
}
}, 10);
window.addEventListener('scroll', debouncedScrollHandler);
// Portfolio item interactions
const portfolioItems = document.querySelectorAll('.portfolio-item');
portfolioItems.forEach(item => {
item.addEventListener('click', () => {
const title = item.querySelector('.portfolio-title').textContent;
console.log(`Clicked on portfolio item: ${title}`);
// Add navigation logic here
});
});
// Smooth page transitions
const pageLinks = document.querySelectorAll('a[href$=".html"]');
pageLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const href = link.getAttribute('href');
// Add fade out effect
document.body.style.opacity = '0';
document.body.style.transition = 'opacity 0.3s ease';
setTimeout(() => {
window.location.href = href;
}, 300);
});
});