I am trying to do a little investigation on which classes are causing an issue with my sticky nav bar where it flickers and re-appears on screen.
What I am planning to do is remove the class attributes to see which ones are having an affect. The issue I seem to be having is that the class elements seem to not be removed. I tried putting them outside the if statement, in the if statement and in the else statement but no luck, I can still see the element-is-sticky
class when I inspect. What do I need to do in order to be able to remove it?
<header id="site-header" class="header-footer-group sticky-element-original element-is-sticky" role="banner" style="margin-top: 0px !important; margin-left: 0px !important; position: fixed; left: 0px; top: 0px; width: 651px; padding: 0px; z-index: 99999;">
...
</header>
<script>
/* When the user scrolls down, hide the navbar. When the user scrolls up, show the navbar */
let scrollTimeout
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
document.getElementsByClassName("element-is-sticky").remove();
document.getElementsByClassName("element-is-sticky").psrentNode.removeChild(document.getElementById("site-header"));
if (prevScrollpos > currentScrollPos) {
document.getElementById("site-header").style.top = "0";
document.getElementsByClassName("element-is-sticky").remove();
document.getElementsByClassName("element-is-sticky").psrentNode.removeChild(document.getElementById("site-header"));
} else {
document.getElementById("site-header").style.top = "-100%";
document.getElementsByClassName("element-is-sticky").remove();
document.getElementsByClassName("element-is-sticky").psrentNode.removeChild(document.getElementById("site-header"));
}
// Event buffering here
clearTimeout(scrollTimeout)
scrollTimeout = setTimeout(function(){
prevScrollpos = currentScrollPos;
},100) // This delay may need adjustment...
}
</script>