I have this script that works perfectly in all browsers:
var position = 0;
window.addEventListener('scroll', function(){
console.log(this.pageYOffset);
if(this.pageYOffset < 1){
document.getElementById('navbar').classList.remove('background');
} else {
document.getElementById('navbar').classList.add('background');
}
if(this.pageYOffset > 200){
document.getElementById('navbar').classList.add('down');
} else {
document.getElementById('navbar').classList.remove('down');
}
if(this.pageYOffset > 200 && this.pageYOffset > position){
document.getElementById('navbar').classList.add('hidden');
} else {
document.getElementById('navbar').classList.remove('hidden');
}
position = this.pageYOffset;
})
The functioning is:
-
When the page is loaded without any scroll or less than 200px, the navbar at the header is displayed with a background by adding the class “background”.
-
If scroll down more than 200px, the navbar hiddes by adding the class “hidden”.
-
At any point of the page below 200px, if scroll up, the navbar shows again by removing the “hidden” class.
It works perfectly. But now I see that in IE11, the class “hidden” is added and then removed at any point of the page for some reason.
Do you know why?