Created
July 2, 2014 06:38
-
-
Save the-affy/cd22e5bebd7feb737c50 to your computer and use it in GitHub Desktop.
on mouse smooth scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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