Skip to content

Instantly share code, notes, and snippets.

@rlivsey
Created April 20, 2016 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlivsey/4dd5ef5633d5e63768e08d6d33a0d969 to your computer and use it in GitHub Desktop.
Save rlivsey/4dd5ef5633d5e63768e08d6d33a0d969 to your computer and use it in GitHub Desktop.
function watchPosition(obj, cb) {
var top = obj.scrollTop;
function checkPosition() {
requestAnimationFrame(function() {
var newTop = obj.scrollTop;
if (top !== newTop) {
cb({ oldValue: top, newValue: newTop });
top = newTop;
}
checkPosition();
});
}
checkPosition();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment