Skip to content

Instantly share code, notes, and snippets.

@the-affy
Created July 2, 2014 06:38
Show Gist options
  • Save the-affy/cd22e5bebd7feb737c50 to your computer and use it in GitHub Desktop.
Save the-affy/cd22e5bebd7feb737c50 to your computer and use it in GitHub Desktop.
on mouse smooth scroll
<script>
//final script scroll
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
var time = 1300;
var distance = 270;
function wheel(event) {
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;
handle();
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
function handle() {
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time);
}
$(document).keydown(function (e) {
switch (e.which) {
//up
case 38:
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - distance
}, time);
break;
//down
case 40:
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() + distance
}, time);
break;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment