Created
March 5, 2015 22:28
-
-
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
This file contains hidden or 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
| function isNearBottom(element, marginPx){ | |
| marginPx = marginPx || 100; | |
| var elementOffsetTop = $(element).offset().top, | |
| nearBottomMargin = $(window).scrollTop() + $(window).height() - elementOffsetTop; | |
| return Math.abs(nearBottomMargin) <= marginPx; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.