-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
222 lines (190 loc) · 7.78 KB
/
script.js
File metadata and controls
222 lines (190 loc) · 7.78 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
document.addEventListener('DOMContentLoaded', function() {
// Preloader
const preloader = document.getElementById('preloader');
setTimeout(() => {
preloader.style.opacity = '0';
setTimeout(() => {
preloader.style.display = 'none';
}, 500);
}, 1000);
// Mobile Menu
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
const closeMenuButton = document.getElementById('close-menu-button');
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.remove('hidden');
mobileMenu.classList.add('flex');
document.body.style.overflow = 'hidden';
});
closeMenuButton.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
mobileMenu.classList.remove('flex');
document.body.style.overflow = 'auto';
});
// Close mobile menu when clicking on a link
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
mobileMenu.classList.remove('flex');
document.body.style.overflow = 'auto';
});
});
// Navbar scroll effect
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('bg-white', 'shadow-md', 'py-4');
navbar.classList.remove('py-6');
} else {
navbar.classList.remove('bg-white', 'shadow-md', 'py-4');
navbar.classList.add('py-6');
}
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Back to top button
const backToTopButton = document.getElementById('back-to-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopButton.classList.remove('opacity-0', 'invisible');
backToTopButton.classList.add('opacity-100', 'visible');
} else {
backToTopButton.classList.add('opacity-0', 'invisible');
backToTopButton.classList.remove('opacity-100', 'visible');
}
});
backToTopButton.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Animate skill bars on scroll
const skillBars = document.querySelectorAll('.skill-bar');
function animateSkillBars() {
skillBars.forEach(bar => {
const width = bar.getAttribute('data-width');
if (isElementInViewport(bar)) {
bar.style.width = width;
}
});
}
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.bottom >= 0
);
}
window.addEventListener('scroll', animateSkillBars);
animateSkillBars(); // Run once on page load
// Portfolio filtering
const filterButtons = document.querySelectorAll('.filter-button');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => {
btn.classList.remove('bg-primary', 'text-white');
btn.classList.add('hover:bg-gray-50');
});
// Add active class to clicked button
button.classList.add('bg-primary', 'text-white');
button.classList.remove('hover:bg-gray-50');
const filterValue = button.getAttribute('data-filter');
portfolioItems.forEach(item => {
if (filterValue === 'all' || item.getAttribute('data-category') === filterValue) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
});
// Testimonial slider
const slider = document.getElementById('slider');
const prevButton = document.getElementById('prev-testimonial');
const nextButton = document.getElementById('next-testimonial');
const dots = document.querySelectorAll('.dot-button');
let currentIndex = 0;
const testimonialCount = document.querySelectorAll('#slider > div').length;
function updateSlider() {
slider.style.transform = `translateX(-${currentIndex * 100}%)`;
// Update dots
dots.forEach((dot, index) => {
if (index === currentIndex) {
dot.classList.add('bg-primary');
dot.classList.remove('bg-gray-300');
} else {
dot.classList.remove('bg-primary');
dot.classList.add('bg-gray-300');
}
});
}
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % testimonialCount;
updateSlider();
});
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + testimonialCount) % testimonialCount;
updateSlider();
});
dots.forEach(dot => {
dot.addEventListener('click', () => {
currentIndex = parseInt(dot.getAttribute('data-index'));
updateSlider();
});
});
// Auto-rotate testimonials
setInterval(() => {
currentIndex = (currentIndex + 1) % testimonialCount;
updateSlider();
}, 5000);
// Contact form submission
const contactForm = document.getElementById('contact-form');
const formSuccess = document.getElementById('form-success');
const formError = document.getElementById('form-error');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Simulate form submission
formSuccess.classList.add('hidden');
formError.classList.add('hidden');
// In a real implementation, you would use fetch() to submit the form
setTimeout(() => {
// For demo purposes, we'll randomly show success or error
if (Math.random() > 0.3) {
formSuccess.classList.remove('hidden');
contactForm.reset();
} else {
formError.classList.remove('hidden');
}
}, 1000);
});
// Intersection Observer for animations
const animateElements = document.querySelectorAll('.animate-fade-in');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('opacity-100', 'translate-y-0');
entry.target.classList.remove('opacity-0', 'translate-y-10');
}
});
}, { threshold: 0.1 });
animateElements.forEach(element => {
element.classList.add('opacity-0', 'translate-y-10', 'transition-all', 'duration-500', 'ease-out');
observer.observe(element);
});
});