Created
February 5, 2010 01:28
-
-
Save revelation/295372 to your computer and use it in GitHub Desktop.
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
// 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