Skip to content

Instantly share code, notes, and snippets.

@prolificjones82
Created September 16, 2015 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prolificjones82/00000756c1822862afbc to your computer and use it in GitHub Desktop.
Save prolificjones82/00000756c1822862afbc to your computer and use it in GitHub Desktop.
Is element in view (jquery)
function isElementInViewport(el)
{
if (typeof jQuery === 'function' && el instanceof jQuery)
{
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= $(window).height() &&
rect.right <= $(window).width()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment