Created
July 20, 2012 12:37
-
-
Save donohoe/3150507 to your computer and use it in GitHub Desktop.
Check if an element in DOM is in viewable area
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
/* Requires jQuery */ | |
function isInView(el) { | |
var docViewTop = $(window).scrollTop(); | |
var docViewBtm = docViewTop + $(window).height(); | |
var elTop = $(el).offset().top; | |
var elBtm = elTop + $(el).height(); | |
return ((elBtm <= docViewBtm) && (elTop >= docViewTop)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment