32 lines
893 B
JavaScript
32 lines
893 B
JavaScript
// Gilroy Hacks Website Source Code -> JS (https://gilroyhacks.com)
|
|
|
|
// 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 > 50) {
|
|
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');
|
|
}
|
|
}
|
|
}
|