I am trying to use a closure, to call a function when the user scrolls on the document in JavaScript.
Therefore i create the constant scroll
and call the inner function via scroll()
when the event 'scroll' happens.
I don't get an error when I'm trying to do this with the code below but the inner function doesn't get called for some reason.
const scroll = scrollEvent();
document.addEventListener("scroll", scroll());
function scrollEvent() {
debugger;
var positions = {pos1: 3, pos2: 5};
return function() {
loadContent(positions);
}
}
Thanks in advance for your help.