-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (37 loc) · 1.29 KB
/
script.js
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
// Toggle dark mode
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
const header = document.querySelector('header');
const footer = document.querySelector('footer');
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark');
header.classList.toggle('dark');
footer.classList.toggle('dark');
themeToggle.textContent = body.classList.contains('dark')
? 'Toggle Light Mode'
: 'Toggle Dark Mode';
});
// Fade-in on scroll
const fadeInElements = document.querySelectorAll('.fade-in');
const handleScroll = () => {
fadeInElements.forEach(el => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight - 100) {
el.classList.add('visible');
}
});
animateSkills();
};
// Animate skill bars
const skillBars = document.querySelectorAll('.bar .progress');
const animateSkills = () => {
skillBars.forEach(bar => {
const rect = bar.getBoundingClientRect();
if (rect.top < window.innerHeight - 100) {
bar.style.width = bar.getAttribute('style').match(/width:\s*(\d+%)/)[1];
}
});
};
// Trigger scroll animations on load and scroll
window.addEventListener('scroll', handleScroll);
window.addEventListener('load', handleScroll);