Skip to content

Instantly share code, notes, and snippets.

@nicopace
Created August 1, 2014 14:04
Show Gist options
  • Save nicopace/4dfea87821d81651a357 to your computer and use it in GitHub Desktop.
Save nicopace/4dfea87821d81651a357 to your computer and use it in GitHub Desktop.
function elementInViewport(el) {
var rect = el.getBoundingClientRect()
return rect.bottom > 0 &&
rect.right > 0 &&
rect.left < (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ &&
rect.top < (window.innerHeight || document.documentElement.clientHeight) /*or $(window).height() */ ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment