Skip to content

Instantly share code, notes, and snippets.

@ericwwsun
Created June 26, 2012 21:12
Show Gist options
  • Save ericwwsun/2999079 to your computer and use it in GitHub Desktop.
Save ericwwsun/2999079 to your computer and use it in GitHub Desktop.
Javascript: On window scrolling, do something based on % of document height
// On window scrolling
$j(window).scroll(function(){
// update the ruler's color based on scroll position
var docHeight = $j(document).height();
var scrollTop = $j(window).scrollTop();
var currPos = scrollTop/docHeight*100;
//console.log( currPos + "%");
if( (currPos > 13 && currPos < 21) || currPos > 64 ) {
//do something in between 13% and 21% and grater than 64%
} else {
//undo things
}
}); // end of scrolling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment