Skip to content

Instantly share code, notes, and snippets.

@jhuesos
Forked from helielson/appearing-filter.js
Last active December 19, 2015 00:20
Show Gist options
  • Save jhuesos/5868280 to your computer and use it in GitHub Desktop.
Save jhuesos/5868280 to your computer and use it in GitHub Desktop.
jQuery.expr[':'].appearing = function(elem) {
var $window = $(window),
windowViewTop = $window.scrollTop(),
windowViewBottom = windowViewTop + $window.height(),
elemTop = $(elem).offset().top,
elemBottom = elemTop + $(elem).height(),
isAppearingFully = ((elemTop >= windowViewTop) && (elemBottom <= windowViewBottom)),
isAppearingBottom = ((windowViewTop > elemTop) && (windowViewTop < elemBottom)),
isAppearingTop = ((windowViewBottom > elemTop) && (windowViewTop < elemBottom));
return isAppearingFully || isAppearingBottom || isAppearingTop;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment