Created
February 15, 2017 10:41
-
-
Save PaulGwamanda/f313d3283a0d7767183bec6e2c04214d to your computer and use it in GitHub Desktop.
Slow down mouse-wheel on scroll by defined miliseconds, requires jquery easing plugin and jquery plugin, add script to main js file
This file contains 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
// Slow down mouse-wheel by 1 second, | |
// add 200 pixels per-scroll | |
// with 150-pixel wheel-delta**/ | |
if (window.addEventListener) | |
window.addEventListener('DOMMouseScroll', wheel, false); | |
window.onmousewheel = document.onmousewheel = wheel; | |
function wheel(event) { | |
// set wheelDelta initial state to 0 | |
var delta = 0; | |
if (event.wheelDelta) | |
delta = event.wheelDelta / 150; | |
else if (event.detail) | |
delta = -event.detail / 3; | |
handle(delta); | |
/** @TODO optimize **/ | |
if (event.preventDefault) | |
event.preventDefault(); | |
event.returnValue = false; | |
} | |
function handle(delta) { | |
// Scroll duration = 1500ms | |
var time = 1200; | |
// Scroll distance = 300pixels | |
var distance = 300; | |
$('html, body').stop().animate({ | |
scrollTop: $(window). | |
scrollTop() - (distance * delta) | |
}, time); | |
} | |
$("div#container") | |
.scroll(function () { | |
var screenheight = parseInt($(document).height()); | |
var scrolledpx = parseInt($("div#container").scrollTop()); | |
var sum = screenheight + scrolledpx; | |
console.log($("div#container").scrollTop()); | |
console.log("screen: " + screenheight); | |
console.log("sum=" + sum); | |
$("div.content").height(sum); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment