-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (36 loc) · 1.18 KB
/
script.js
File metadata and controls
38 lines (36 loc) · 1.18 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
const themeToggle = document.getElementById('themeToggle');
const root = document.documentElement;
function applyTheme(theme){
if(theme === 'dark'){
root.setAttribute('data-theme','dark');
themeToggle.textContent = '☀️';
themeToggle.setAttribute('aria-pressed','true');
} else {
root.removeAttribute('data-theme');
themeToggle.textContent = '🌙';
themeToggle.setAttribute('aria-pressed','false');
}
}
const saved = localStorage.getItem('theme') || 'light';
applyTheme(saved);
themeToggle.addEventListener('click', () => {
const next = (root.getAttribute('data-theme') === 'dark')? 'light' : 'dark';
applyTheme(next);
localStorage.setItem('theme', next);
});
const cards = document.querySelectorAll('.card');
if('IntersectionObserver' in window){
const obs = new IntersectionObserver(entries=>{
entries.forEach(e=>{
if(e.isIntersecting){
const el = e.target;
const idx = Array.from(cards).indexOf(el);
setTimeout(()=>{
el.classList.add('animate-in');
obs.unobserve(el);
}, idx * 150);
}
});
},{threshold:0.18});
cards.forEach(c=>{ obs.observe(c); });
}