-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
185 lines (157 loc) · 5.23 KB
/
script.js
File metadata and controls
185 lines (157 loc) · 5.23 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
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
// Smooth scrolling 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) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar background change on scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 100) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
navbar.style.boxShadow = 'none';
}
});
// Scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll('.timeline-item, .project-card, .skill-category, .contact-item, .stat-item');
animateElements.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
});
// Active navigation link highlighting
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
window.addEventListener('scroll', () => {
let current = '';
const scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// Typing effect for hero title (optional enhancement)
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Initialize typing effect when page loads
document.addEventListener('DOMContentLoaded', () => {
const heroTitle = document.querySelector('.hero-title');
if (heroTitle) {
const originalText = heroTitle.innerHTML;
// Uncomment the line below to enable typing effect
// typeWriter(heroTitle, originalText, 50);
}
});
// Add loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Contact form validation (if you add a contact form later)
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
// Add some interactive hover effects
document.addEventListener('DOMContentLoaded', () => {
// Add hover effects to skill tags
const skillTags = document.querySelectorAll('.skill-tag');
skillTags.forEach(tag => {
tag.addEventListener('mouseenter', () => {
tag.style.transform = 'translateY(-3px) scale(1.05)';
});
tag.addEventListener('mouseleave', () => {
tag.style.transform = 'translateY(0) scale(1)';
});
});
// Add hover effects to project cards
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-8px)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0)';
});
});
});
// Parallax effect for hero section (subtle)
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero) {
const rate = scrolled * -0.5;
hero.style.transform = `translateY(${rate}px)`;
}
});
// Add CSS for active navigation link
const style = document.createElement('style');
style.textContent = `
.nav-link.active {
color: #2563eb !important;
}
.nav-link.active::after {
width: 100% !important;
}
body.loaded {
opacity: 1;
}
body {
opacity: 0;
transition: opacity 0.5s ease;
}
`;
document.head.appendChild(style);