Reputation: 945
I am trying to scroll one page at any scroll event but, multiple scroll events are triggered when we use mouse wheel in my example.
I want to scroll one screen at a time when mouse or keyboard is used to scroll but the event as below is triggered multiple times for mouse wheel scroll
window.onscroll = function (e) {
e.preventDefault();}
Upvotes: 1
Views: 619
Reputation: 5681
You can use a setTimeout
to detect the end of scroll event and then run your code like below.
var t;
addEventListener('scroll', scrollEndFunc)
function scrollEndFunc(e) {
clearTimeout(t);
t = setTimeout(function(){
//todo stuff
}, 600) // wait untill 600ms, if no scroll then
// execute actual function else cancel it.
}
Here is the Edit to codepen
Upvotes: 2