Skip to content

Instantly share code, notes, and snippets.

@revelation
Created February 5, 2010 01:28
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 revelation/295372 to your computer and use it in GitHub Desktop.
Save revelation/295372 to your computer and use it in GitHub Desktop.
// Let's see this in action. Consider a lowly div
// ( wrap it in JQuery with $('div') ):
// how many pixels of content have been viewed
// (already scrolled + current view)?
// formula : scrollTop + outerHeight
$('div').scrollTop() + $('div').outerHeight();
// how many pixels are left to scroll?
// formula : scrollHeight - (scrollTop + outerHeight)
$('div')[0].scrollHeight - ($('div').scrollTop + $('div').outerHeight);
// have we scrolled to the bottom?
// formula : scrollHeight / (scrollTop + outerHeight),
// a value of 1 means scrolled to bottom.
var element = $('div');
var percent_scrolled = element[0].scrollHeight /
(element.scrollTop() + element.outerHeight());
var answer = percent_scrolled == 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment