Created
June 2, 2012 12:04
-
-
Save luis-almeida/2858053 to your computer and use it in GitHub Desktop.
Extending jQuery with an "inview" selector to select elements that are in the visible part of the page (at least partially).
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
$.extend($.expr[':'], { | |
inview: function ( el ) { | |
var $e = $( el ), | |
$w = $( window ), | |
wt = $w.scrollTop(), | |
wb = wt + $w.height(), | |
et = $e.offset().top, | |
eb = et + $e.height(); | |
return eb >= wt && et <= wb; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment