I want to get an event when a user starts scrolling. There is a way available in JQuery using scrollstart
.
Is there any way we can achieve the same in vanilla JavaScript?
I want to get an event when a user starts scrolling. There is a way available in JQuery using scrollstart
.
Is there any way we can achieve the same in vanilla JavaScript?
If we tweak this answer a bit, we can achieve both, scroll start and end.
var timer = null;
window.addEventListener('scroll', function() {
if(timer === null) {
console.log('Scroll Started');
}
if(timer !== null) {
clearTimeout(timer);
}
timer = setTimeout(function() {
console.log('Scroll Stopped');
timer = null;
}, 150);
}, false);