Skip to content

Instantly share code, notes, and snippets.

@fdn
Created January 16, 2014 23:41
Show Gist options
  • Save fdn/8465684 to your computer and use it in GitHub Desktop.
Save fdn/8465684 to your computer and use it in GitHub Desktop.
isInViewport(el)
// via http://blog.adtile.me/2014/01/16/a-dive-into-plain-javascript/
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment