-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
244 lines (213 loc) · 7.63 KB
/
script.js
File metadata and controls
244 lines (213 loc) · 7.63 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
// Initialize Locomotive Scroll
// const scroll = new LocomotiveScroll({
// el: document.querySelector('#main1'),
// smooth: true,
// lerp: 0.04,
// smartphone: {
// smooth: true,
// lerp: 0.05
// },
// tablet: {
// smooth: true,
// lerp: 0.05
// }
// });
// Initialize Typed.js for text animation
document.addEventListener('DOMContentLoaded', function() {
// Check if typed-text element exists
const typedElement = document.querySelector('.typed-text');
if (typedElement) {
const typed = new Typed('.typed-text', {
strings: ['Web Developer', 'Computer Engineering Student', 'Frontend Enthusiast'],
typeSpeed: 50,
backSpeed: 30,
loop: true,
backDelay: 1500,
startDelay: 500
});
}
// Set current year in footer
const currentYearElement = document.getElementById('current-year');
if (currentYearElement) {
currentYearElement.textContent = new Date().getFullYear();
}
});
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function() {
const menuToggle = document.querySelector('.menu-toggle');
const mainNav = document.querySelector('.main-nav');
const barsIcon = document.querySelector('.menu-toggle .fa-bars');
const timesIcon = document.querySelector('.menu-toggle .fa-times');
// Function to check if we're in mobile view
function isMobileView() {
return window.innerWidth <= 768;
}
if (menuToggle && mainNav) {
menuToggle.addEventListener('click', function() {
// Only toggle if in mobile view
if (isMobileView()) {
mainNav.classList.toggle('active');
menuToggle.classList.toggle('active');
document.body.classList.toggle('menu-open'); // Add this class to prevent scrolling
// Toggle visibility of icons
if (barsIcon && timesIcon) {
barsIcon.style.display = barsIcon.style.display === 'none' ? 'block' : 'none';
timesIcon.style.display = timesIcon.style.display === 'none' ? 'block' : 'none';
}
}
});
}
// Close menu when clicking on a link
const navLinks = document.querySelectorAll('.main-nav a');
navLinks.forEach(link => {
link.addEventListener('click', function() {
if (isMobileView() && mainNav.classList.contains('active')) {
mainNav.classList.remove('active');
menuToggle.classList.remove('active');
document.body.classList.remove('menu-open');
// Reset icons
if (barsIcon && timesIcon) {
barsIcon.style.display = 'block';
timesIcon.style.display = 'none';
}
}
});
});
// Close menu when clicking outside
document.addEventListener('click', function(e) {
if (mainNav && mainNav.classList.contains('active')) {
if (!mainNav.contains(e.target) && !menuToggle.contains(e.target)) {
mainNav.classList.remove('active');
menuToggle.classList.remove('active');
document.body.classList.remove('menu-open');
// Reset icons
if (barsIcon && timesIcon) {
barsIcon.style.display = 'block';
timesIcon.style.display = 'none';
}
}
}
});
// Reset menu state on window resize
window.addEventListener('resize', function() {
if (!isMobileView() && mainNav.classList.contains('active')) {
mainNav.classList.remove('active');
menuToggle.classList.remove('active');
document.body.classList.remove('menu-open');
// Reset icons
if (barsIcon && timesIcon) {
barsIcon.style.display = 'block';
timesIcon.style.display = 'none';
}
}
});
});
// Intersection Observer for animation on scroll
document.addEventListener('DOMContentLoaded', function() {
const fadeElements = document.querySelectorAll('.skill-card, .project-card, .timeline-item');
const fadeObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fadeIn');
fadeObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.1
});
fadeElements.forEach(element => {
fadeObserver.observe(element);
});
});
// Add active class to nav items on scroll
document.addEventListener('DOMContentLoaded', function() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.main-nav a');
function highlightNavOnScroll() {
const scrollPosition = window.scrollY;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', highlightNavOnScroll);
window.addEventListener('load', highlightNavOnScroll);
});
// Navbar scroll effect
window.addEventListener('scroll', function() {
const header = document.getElementById('pageheader');
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Check if it's a mobile device
function isMobile() {
return window.innerWidth <= 768;
}
// Add resize handler for responsive adjustments
window.addEventListener('resize', function() {
// Function to check if we're in mobile view
function isMobileView() {
return window.innerWidth <= 768;
}
// Reset menu state when resizing from mobile to desktop
const mainNav = document.querySelector('.main-nav');
const menuToggle = document.querySelector('.menu-toggle');
if (!isMobileView() && mainNav && mainNav.classList.contains('active')) {
// If resizing to desktop and menu is open, close it
mainNav.classList.remove('active');
if (menuToggle) {
menuToggle.classList.remove('active');
const icon = menuToggle.querySelector('i');
if (icon) {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
}
document.body.classList.remove('menu-open');
}
if (isMobile()) {
// Mobile-specific adjustments
if (typeof scroll !== 'undefined' && scroll) {
scroll.update();
}
} else {
// Desktop-specific adjustments
if (typeof scroll !== 'undefined' && scroll) {
scroll.update();
}
}
});
// Fix excessive scrolling
document.addEventListener('DOMContentLoaded', function() {
// Function to adjust container height to prevent extra scrolling
function adjustContainerHeight() {
const windowHeight = window.innerHeight;
const documentHeight = document.documentElement.scrollHeight;
const footerHeight = document.querySelector('footer').offsetHeight;
// Check if document is taller than it needs to be
if (documentHeight > windowHeight + footerHeight + 100) {
// Trim excess height from main container
const excessHeight = documentHeight - (windowHeight + footerHeight);
const main = document.getElementById('main1');
if (main) {
main.style.marginBottom = `-${excessHeight}px`;
}
}
}
// Run on page load
adjustContainerHeight();
// Run when window is resized
window.addEventListener('resize', adjustContainerHeight);
});