Created
March 9, 2020 17:08
-
-
Save Bachana123/18436b53429e97fbde7cf18981e517d4 to your computer and use it in GitHub Desktop.
scroll speed
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
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() ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment