Skip to content

Instantly share code, notes, and snippets.

@spac3unit
Created August 27, 2016 19:16
Show Gist options
  • Save spac3unit/0c252d2d8cb8d4a9f893d804b465fce1 to your computer and use it in GitHub Desktop.
Save spac3unit/0c252d2d8cb8d4a9f893d804b465fce1 to your computer and use it in GitHub Desktop.
// Depency on Jquery + http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js [Must Include]
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
function wheel(event) {
var delta = 0;
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;
handle(delta);
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
function handle(delta) {
var time = 1000; // delay time
var distance = 300; // delta point
// Dom where it will apply
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment