Skip to content

Instantly share code, notes, and snippets.

@daydarkln
Created June 7, 2018 14:04
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 daydarkln/95c4952727763de62be83cc0d6e7a966 to your computer and use it in GitHub Desktop.
Save daydarkln/95c4952727763de62be83cc0d6e7a966 to your computer and use it in GitHub Desktop.
This one return true if element is locate in viewport cooordinates
var elementInViewport = function(elem) {
var rect = elem.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.top <= (window.innerHeight || document.documentElement.clientHeight)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment