Skip to content

Instantly share code, notes, and snippets.

@mmaelzer
Created July 8, 2013 03:18
Show Gist options
  • Save mmaelzer/5945996 to your computer and use it in GitHub Desktop.
Save mmaelzer/5945996 to your computer and use it in GitHub Desktop.
jQuery - get percentage scrolled from top/bottom
$.fn.percentScrolledTop = function() {
var vals = [];
this.each(function() {
vals.push(+($(this).scrollTop() / this.scrollHeight));
});
return vals.length === 1 ? vals[0] : vals;
};
$.fn.percentScrolledBottom = function() {
var vals = [];
this.each(function() {
var $this = $(this);
vals.push(($this.scrollTop() + $this.height()) / this.scrollHeight);
});
return vals.length === 1 ? vals[0] : vals;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment