Advertisement
salmancreation

isInViewport.js

Dec 24th, 2023
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2.  * Determine if an element is in the viewport
  3.  * (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com
  4.  * @param  {Node}    elem The element
  5.  * @return {Boolean}      Returns true if element is in the viewport
  6.  */
  7. var isInViewport = function (elem) {
  8.     var distance = elem.getBoundingClientRect();
  9.     return (
  10.         distance.top >= 0 &&
  11.         distance.left >= 0 &&
  12.         distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
  13.         distance.right <= (window.innerWidth || document.documentElement.clientWidth)
  14.     );
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement