I have created a site where users are able to scroll through a gallery using mouse scroll or arrow up/down. It is working like I want it to, and changing one image pr scroll
This is pretty much what DC_ suggested. Figured I'd post this since it's an actual implementation.
// similar to _.debounce, but was having issues with it, so I made this.
function rateLimit(func, time){
var callback = func,
waiting = false,
context = this;
var rtn = function(){
if(waiting) return;
waiting = true;
var args = arguments;
setTimeout(function(){
waiting = false;
callback.apply(context, args);
}, time);
};
return rtn;
}
function onWheel(e){
// Add your code here
}
// will only fire a maximum of 10 times a second
var debouncedOnWheel = rateLimit(onWheel, 100);
window.addEventListener("wheel", debouncedOnWheel);