Advertisement
rdsedmundo

isInViewport

Sep 28th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isInViewport(element) {
  2.   var rect = element.getBoundingClientRect();
  3.   var html = document.documentElement;
  4.   return (
  5.     rect.top >= 0 &&
  6.     rect.left >= 0 &&
  7.     rect.bottom <= (window.innerHeight || html.clientHeight) &&
  8.     rect.right <= (window.innerWidth || html.clientWidth)
  9.   );
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement