Skip to content

Instantly share code, notes, and snippets.

@luis-almeida
Created June 2, 2012 12:04
Show Gist options
  • Save luis-almeida/2858053 to your computer and use it in GitHub Desktop.
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).
$.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