Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (39 loc) · 1.49 KB
/
Copy pathscript.js
File metadata and controls
43 lines (39 loc) · 1.49 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
// Custom cursor
const cursor = document.getElementById('cursor');
const dot = document.getElementById('cursor-dot');
document.addEventListener('mousemove', e => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
dot.style.left = e.clientX + 'px';
dot.style.top = e.clientY + 'px';
});
// Scroll reveal
const reveals = document.querySelectorAll('.reveal');
const obs = new IntersectionObserver(entries => {
entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add('visible'); } });
}, { threshold: 0.12 });
reveals.forEach(r => obs.observe(r));
// Animate progress bars when visible
const barObs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
const bar = e.target.querySelector('.aug-bar');
if (bar) bar.style.width = bar.dataset.width + '%';
}
});
}, { threshold: 0.3 });
document.querySelectorAll('.aug-item').forEach(i => barObs.observe(i));
// Nav active highlight on scroll
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => {
const y = window.scrollY + 120;
sections.forEach(s => {
const a = document.querySelector(`.nav-links a[href="#${s.id}"]`);
if (!a) return;
if (s.offsetTop <= y && s.offsetTop + s.offsetHeight > y) {
a.style.color = 'var(--cyan)';
} else {
a.style.color = '';
}
});
});