Skip to content

Instantly share code, notes, and snippets.

@PaulGwamanda
Created February 15, 2017 10:41
Show Gist options
  • Save PaulGwamanda/f313d3283a0d7767183bec6e2c04214d to your computer and use it in GitHub Desktop.
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
// 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