Witam,
w jaki sposób zwrócić wartość 'up' lub 'down', po wywołaniu helpera?
Założenie jest takie, żeby zwrócić wartość obecnego kierunku scrolla. Np.:
if(scrollDetect==='down') {
//do something
}
i, aby był on wykonywany na scroll.
const scrollDetect = function(){
var lastScroll = 0;
var direction = 'default';
window.addEventListener('scroll', function test() {
let currentScroll = document.documentElement.scrollTop || document.body.scrollTop; // Get Current Scroll Value
if (currentScroll > 0 && lastScroll <= currentScroll) {
direction = 'down';
document.getElementById("scrollLoc").innerHTML = direction;
} else {
direction = 'up';
document.getElementById("scrollLoc").innerHTML = direction;
}
lastScroll = currentScroll;
return direction;
});
return direction;
}
alert(scrollDetect());