I've found in IE (and IE Edge), I get too many scroll events for too long a time. A flick on the mousepad can result in anywhere from 1-1.8 seconds of scroll events being fired.
I cannot set a throttle of 2 seconds as that's too long and will cause users to get frustrated.
I tried also checking that the events were not too close together (50ms or less) but if the user executes a new scroll during the previous one going and their scroll starts at 45ms after the last "extra" scroll event was fired by IE, then it starts a whole new 1-1.8 seconds of events (and this can go on forever).
The only thing that would solve this is if I can have a scroll start (similar to mousedown
).
My incorrect attempt at a solution:
var lastEventTime = 0;
var lastTime = 0;
function scrollListener()
{
let now = new Date().getTime();
//Not listening, still scrolling
//Delay of 1 second isn't long enough
//50 milliseconds works 90% of the time, but I can initiate under that sometimes
if ( now < ( lastTime + 1000 ) || now - lastEventTime < 50 )
)
{
//Update event time
lastEventTime = now;
//Don't do rest of function
return;
}
...elided...
}