-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
199 lines (173 loc) · 6.1 KB
/
script.js
File metadata and controls
199 lines (173 loc) · 6.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
// Smooth scroll for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - 100;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Navbar scroll effect
const nav = document.querySelector('.nav');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
nav.style.background = 'rgba(255, 255, 255, 0.95)';
nav.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.05)';
} else {
nav.style.background = 'rgba(255, 255, 255, 0.8)';
nav.style.boxShadow = 'none';
}
});
// Animate skill bars on scroll
const animateSkillBars = () => {
const skillBars = document.querySelectorAll('.skill-fill');
const skillsSection = document.getElementById('skills');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const skillBar = entry.target;
const width = skillBar.getAttribute('data-width');
setTimeout(() => {
skillBar.style.width = width + '%';
}, 200);
observer.unobserve(skillBar);
}
});
}, {
threshold: 0.3
});
skillBars.forEach(bar => {
observer.observe(bar);
});
};
// Initialize skill bar animation
animateSkillBars();
// Simple fade in animation on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const fadeObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
fadeObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements for fade-in animation
document.querySelectorAll('.work-card, .testimonial-card, .about-text, .contact-method, .skill-group, .portfolio-item').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
fadeObserver.observe(el);
});
// Hero content visible immediately
const heroMain = document.querySelector('.hero-main');
if (heroMain) {
heroMain.style.opacity = '1';
}
// Animated counter for stats
const animateCounter = (element, target, suffix = '') => {
const duration = 2000;
const increment = target / (duration / 16);
let current = 0;
const updateCounter = () => {
current += increment;
if (current < target) {
element.textContent = Math.floor(current) + suffix;
requestAnimationFrame(updateCounter);
} else {
element.textContent = target + suffix;
}
};
updateCounter();
};
// Observe stats section for counter animation
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statNumbers = entry.target.querySelectorAll('.stat-number');
statNumbers.forEach(stat => {
const target = parseInt(stat.getAttribute('data-target'));
const suffix = stat.getAttribute('data-target') === '100' ? '%' : '+';
animateCounter(stat, target, suffix);
});
statsObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
const heroStats = document.querySelector('.hero-stats');
if (heroStats) {
statsObserver.observe(heroStats);
}
// Removed parallax effects for simpler experience
// Active navigation link highlighting
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop - 150) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// Add active state styling
const style = document.createElement('style');
style.textContent = `
.nav-links a.active {
color: var(--text);
}
.nav-links a.active::after {
width: 100%;
}
`;
document.head.appendChild(style);
// Set current year dynamically
const currentYearElement = document.getElementById('current-year');
if (currentYearElement) {
currentYearElement.textContent = new Date().getFullYear();
}
// Portfolio filter functionality
const filterButtons = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
const filterValue = button.getAttribute('data-filter');
portfolioItems.forEach(item => {
const categories = item.getAttribute('data-category').split(' ');
if (filterValue === 'all' || categories.includes(filterValue)) {
item.style.display = 'block';
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'translateY(0)';
}, 10);
} else {
item.style.opacity = '0';
item.style.transform = 'translateY(20px)';
setTimeout(() => {
item.style.display = 'none';
}, 300);
}
});
});
});