Skip to content

Instantly share code, notes, and snippets.

@socmia
Created October 25, 2019 01:40
Show Gist options
  • Save socmia/69fba84eeed145919fcc1e1067f61424 to your computer and use it in GitHub Desktop.
Save socmia/69fba84eeed145919fcc1e1067f61424 to your computer and use it in GitHub Desktop.
document.addEventListener("scroll", scrollHandler, true);
function scrollHandler() {
currentScrollPosition = document.documentElement.scrollTop;
for (var i=1; i<=positionArray.length; i++){
if (currentScrollPosition>=positionArray[i-1] && currentScrollPosition < positionArray[i]) {
var currentActive = document.getElementsByClassName('is-active')[0];
if (currentActive != undefined){
currentActive.classList.remove('is-active');
}
quickLinks[i-1].classList.add('is-active');
break;
}
if (currentScrollPosition>positionArray[positionArray.length-1]){
var currentActive = document.getElementsByClassName('is-active');
var currentActive = document.getElementsByClassName('is-active')[0];
if (currentActive != undefined){
currentActive.classList.remove('is-active');
}
quickLinks[quickLinks.length-1].classList.add('is-active');
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment