-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (19 loc) · 819 Bytes
/
script.js
File metadata and controls
23 lines (19 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const themeToggleBtn = document.getElementById('theme-toggle');
const savedTheme = localStorage.getItem('theme') || 'light';
document.body.classList.toggle('dark', savedTheme === 'dark');
themeToggleBtn.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
themeToggleBtn.addEventListener('click', () => {
const isDark = document.body.classList.toggle('dark');
themeToggleBtn.textContent = isDark ? '☀️' : '🌙';
localStorage.setItem('theme', isDark ? 'dark' : 'light');
});
function onScrollAnimate() {
document.querySelectorAll('.animate').forEach(el => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight - 50) {
el.classList.add('visible');
}
});
}
window.addEventListener('scroll', onScrollAnimate);
window.addEventListener('load', onScrollAnimate);