Skip to content

Instantly share code, notes, and snippets.

@lancevo
Created March 5, 2015 22:28
Show Gist options
  • Select an option

  • Save lancevo/19f5a5349ee5827242c1 to your computer and use it in GitHub Desktop.

Select an option

Save lancevo/19f5a5349ee5827242c1 to your computer and use it in GitHub Desktop.
check an element to see if it nears the bottom of the view port
function isNearBottom(element, marginPx){
marginPx = marginPx || 100;
var elementOffsetTop = $(element).offset().top,
nearBottomMargin = $(window).scrollTop() + $(window).height() - elementOffsetTop;
return Math.abs(nearBottomMargin) <= marginPx;
}
@lancevo

lancevo commented Mar 5, 2015

Copy link
Copy Markdown
Author

It's useful for something like an accordion, when user clicks on a header at the bottom of the screen, it'd enhance user experience to scroll up the item and expand the content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment