gilroyhacks.com/js/scroll_nav.js

31 lines
825 B
JavaScript
Raw Normal View History

2022-05-30 00:57:34 -07:00
// Toggle the .pa-fixed-header class when the user
// scroll 100px
window.onscroll = () => {scrollNavbar()};
scrollNavbar = () => {
// Target elements
const navBar = document.getElementById("navBar");
const links = document.querySelectorAll("#navBar a");
if (document.documentElement.scrollTop > 100) {
navBar.classList.add("pa-fixed-header");
// Change the color of links on scroll
for (let i = 0; i < links.length; i++) {
const element = links[i];
element.classList.add('text-black');
}
} else {
navBar.classList.remove("pa-fixed-header");
// Change the color of links back to default
for (let i = 0; i < links.length; i++) {
const element = links[i];
element.classList.remove('text-black');
}
}
}