-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
173 lines (147 loc) · 6.23 KB
/
script.js
File metadata and controls
173 lines (147 loc) · 6.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
document.addEventListener('DOMContentLoaded', () => {
/* --- Theme Toggle --- */
const themeToggleBtn = document.getElementById('theme-toggle');
const themeIcon = themeToggleBtn.querySelector('i');
// Check for saved theme preference or default to dark
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
document.documentElement.removeAttribute('data-theme');
themeIcon.classList.replace('fa-sun', 'fa-moon');
} else {
document.documentElement.setAttribute('data-theme', 'dark');
themeIcon.classList.replace('fa-moon', 'fa-sun');
}
// Toggle Theme
themeToggleBtn.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
// Trigger Sun/Moon Icon Animation
themeIcon.classList.add('animate-mode-spin');
// Wait for it to spin out, then swap and spin back in
setTimeout(() => {
if (currentTheme === 'dark') {
document.documentElement.removeAttribute('data-theme');
localStorage.setItem('theme', 'light');
themeIcon.classList.replace('fa-sun', 'fa-moon');
} else {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
themeIcon.classList.replace('fa-moon', 'fa-sun');
}
themeIcon.classList.remove('animate-mode-spin');
}, 150);
// Trigger Main Branding Logo Animation
const mainLogo = document.getElementById('main-logo');
if (mainLogo) {
mainLogo.classList.remove('animate-logo-flip');
void mainLogo.offsetWidth; // Force a DOM reflow so the animation restarts
mainLogo.classList.add('animate-logo-flip');
}
});
/* --- Navbar Scroll Effect & Scroll Progress --- */
const navbar = document.getElementById('navbar');
const progressBar = document.getElementById('myBar');
window.addEventListener('scroll', () => {
// Sticky Navbar styling
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
// Scroll Progress Bar calculation
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (winScroll / height) * 100;
progressBar.style.width = scrolled + "%";
});
/* --- Scroll Spy & Smooth Scroll --- */
const sections = document.querySelectorAll('.section');
// Highlight Active Navbar Link
const navItems = document.querySelectorAll('.nav-link');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollY >= (sectionTop - sectionHeight / 3)) {
current = section.getAttribute('id');
}
});
navItems.forEach(a => {
a.classList.remove('active');
if (a.getAttribute('href') === `#${current}`) {
a.classList.add('active');
}
});
});
// Smooth Scrolling for Internal Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if(target) {
const offset = 70; // Adjust for sticky navbar
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - offset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
});
});
/* --- Scroll Reveal Animations --- */
const revealElements = document.querySelectorAll('.reveal');
const revealOnScroll = () => {
const windowHeight = window.innerHeight;
const elementVisible = 150;
revealElements.forEach(el => {
const elementTop = el.getBoundingClientRect().top;
if (elementTop < windowHeight - elementVisible) {
el.classList.add('active');
}
});
}
window.addEventListener('scroll', revealOnScroll);
revealOnScroll(); // Trigger once on load
/* --- Typing Animation --- */
const typingTextElement = document.querySelector('.typing-text');
const words = ["Full Stack Developer", "AI/ML Enthusiast", "Problem Solver"];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typeDelay = 150;
const type = () => {
const currentWord = words[wordIndex];
if (isDeleting) {
typingTextElement.textContent = currentWord.substring(0, charIndex - 1);
charIndex--;
typeDelay = 100; // Speed up erasing
} else {
typingTextElement.textContent = currentWord.substring(0, charIndex + 1);
charIndex++;
typeDelay = 150;
}
// If completed typing a word
if (!isDeleting && charIndex === currentWord.length) {
isDeleting = true;
typeDelay = 1500; // Pause before erasing
}
// If completed erasing a word
else if (isDeleting && charIndex === 0) {
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length; // Move to next word
typeDelay = 500; // Pause before typing new word
}
setTimeout(type, typeDelay);
}
/* --- Accordion Logic for Resume --- */
const resumeHeaders = document.querySelectorAll('.collapsible-header');
resumeHeaders.forEach(header => {
header.addEventListener('click', () => {
const parentItem = header.closest('.resume-item');
parentItem.classList.toggle('active');
});
});
// Start typing animation slightly after load
setTimeout(type, 1000);
});