//Scroll Up and Scroll Down In JavaScript
var scroll_y = document.getElementById("div_top_header");
// Initial state
var scrollPos = 0;
// adding scroll event
window.addEventListener('scroll', function () {
// detects new state and compares it with the new one
if ((document.body.getBoundingClientRect()).top > scrollPos){
// document.getElementById('info-box').setAttribute('data-scroll-direction', 'UP');
console.log('UP');
scroll_y.style.display = "block";
}
else{
// document.getElementById('info-box').setAttribute('data-scroll-direction', 'DOWN');
console.log('down');
scroll_y.style.display = "none";
}
// saves the new position for iteration.
scrollPos = (document.body.getBoundingClientRect()).top;
});
No comments:
Post a Comment