50projects50days/sticky-navigation/script.js

10 lines
251 B
JavaScript
Raw Permalink Normal View History

2020-11-17 19:00:55 +00:00
const nav = document.querySelector('.nav')
window.addEventListener('scroll', fixNav)
function fixNav() {
if(window.scrollY > nav.offsetHeight + 150) {
nav.classList.add('active')
} else {
nav.classList.remove('active')
}
}