I need to check if user stops scrolling some element on website (stop scrolling using mouse wheel not website) so I write some function in native JS for that:
document.addEventListener("DOMContentLoaded", function(event) {
scroller();
});
function scroller(){
var scrolling_area = document.getElementById("scroll-area");
console.log(scrolling_area); //shows good div
scrolling_area.addEventListener('scroll', function (event) {
event.preventDefault();
clearTimeout(isScrolling);
isScrolling = setTimeout(function () {
console.log('User stops scrolling');
}, 66);
}, false);
}
<div id="scroll-area" style="background:#ccc; height:1000px"></div>
function scroller(){
var scrolling_area = document.getElementById("scroll-area");
console.log(scrolling_area); //shows good div
scrolling_area.addEventListener('scroll', function (event) {
event.preventDefault();
clearTimeout(isScrolling);
isScrolling = setTimeout(function () {
console.log('User stops scrolling');
}, 66);
}, false);
}
First console.log() shows good div, also if I use window instead of #scrolling_area element everything works fine.
window.addEventListener('scroll', function (event) {...});
But when I'm trying to use my div element I can't see any results. I also tried use listener with and without preventDefault() function. Am I doing something wrong or the div#scrolling_area may cause some issues?