Skip to content

Instantly share code, notes, and snippets.

@lucasprogamer
Last active August 30, 2019 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasprogamer/911a065ac9a7d84d0d3a8a072fdd3c89 to your computer and use it in GitHub Desktop.
Save lucasprogamer/911a065ac9a7d84d0d3a8a072fdd3c89 to your computer and use it in GitHub Desktop.
// SCROLL EVENT CAPTURE //
var wheel = document.getElementById('wheel');
function report(ammout) {
clearTimeout(time);
if(ammout > 0){
time = setTimeout(previousPage, 300);
}else{
time = setTimeout(nextPage, 300);
}
}
function callback(event) {
var normalized;
if (event.wheelDelta) {
normalized = (event.wheelDelta % 120 - 0) == -0 ? event.wheelDelta / 120 : event.wheelDelta / 12;
} else {
var rawAmmount = event.deltaY ? event.deltaY : event.detail;
normalized = -(rawAmmount % 3 ? rawAmmount * 10 : rawAmmount / 3);
}
report(normalized);
}
var event = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
window.addEventListener(event, callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment