I'm trying to think of a way to measure the velocity of a scroll event, that would produce some sort of a number which will represent the speed (distance from scroll point A to point B relative to the time it took).
var checkScrollSpeed = (function(settings){ settings = settings || {}; var lastPos, newPos, timer, delta, delay = settings.delay || 50; // in "ms" (higher means lower fidelity ) function clear() { lastPos = null; delta = 0; } clear(); return function(){ newPos = window.scrollY; if ( lastPos != null ){ // && newPos < maxScroll delta = newPos - lastPos; } lastPos = newPos; clearTimeout(timer); timer = setTimeout(clear, delay); return delta; }; })(); // listen to "scroll" event window.onscroll = function(){ console.log( checkScrollSpeed() ); };
Demo page: http://codepen.io/vsync/pen/taAGd/
Simplified demo: http://jsbin.com/mapafadako/edit?js,console,output
Here is a script I just custom made for your issue. JS Bin
You can view the speed of scroll in the console log. It gives negative values for scrolling up and positive for scrolling down. The actual placement of the scroll bar is constantly updated in the scroll window for more information to glean. This should get you going in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With