first draft
This commit is contained in:
36
script.js
36
script.js
@@ -1,14 +1,24 @@
|
||||
// https://twitter.com/uixmat
|
||||
// ─── Scroll reveal ─────────────────────────────────────────
|
||||
const reveals = document.querySelectorAll('.reveal');
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
entries.forEach(e => {
|
||||
if (e.isIntersecting) {
|
||||
e.target.classList.add('visible');
|
||||
observer.unobserve(e.target);
|
||||
}
|
||||
});
|
||||
}, { threshold: 0.1, rootMargin: '0px 0px -40px 0px' });
|
||||
reveals.forEach(el => observer.observe(el));
|
||||
|
||||
function scrollNav() {
|
||||
$('.nav a').click(function(){
|
||||
$(".active").removeClass("active");
|
||||
$(this).addClass("active");
|
||||
|
||||
$('html, body').stop().animate({
|
||||
scrollTop: $($(this).attr('href')).offset().top - 160
|
||||
}, 300);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
scrollNav();
|
||||
// ─── Active nav link on scroll ──────────────────────────────
|
||||
const sections = document.querySelectorAll('section[id]');
|
||||
const navLinks = document.querySelectorAll('.nav-links a');
|
||||
window.addEventListener('scroll', () => {
|
||||
let current = '';
|
||||
sections.forEach(s => {
|
||||
if (window.scrollY >= s.offsetTop - 120) current = s.id;
|
||||
});
|
||||
navLinks.forEach(a => {
|
||||
a.style.color = a.getAttribute('href') === `#${current}` ? 'var(--mauve)' : '';
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user