Created
April 15, 2015 20:05
-
-
Save izumskee/af1a7469b9bbfc287464 to your computer and use it in GitHub Desktop.
Calculate Scroll Speed
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
// Calculate Scroll Speed | |
var lastOffset = $(window).scrollTop(); | |
var lastDate = new Date().getTime(); | |
$(window).scroll(function(e) { | |
var delayInMs = e.timeStamp - lastDate; | |
var offset = scrollTopValue - lastOffset; | |
var speedInpxPerMs = offset / delayInMs; | |
var scrollSpeed = Math.abs(speedInpxPerMs.toFixed(2)); | |
console.log(scrollSpeed); | |
lastDate = e.timeStamp; | |
lastOffset = scrollTopValue; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment