Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- * Determine if an element is in the viewport
- * (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com
- * @param {Node} elem The element
- * @return {Boolean} Returns true if element is in the viewport
- */
- var isInViewport = function (elem) {
- var distance = elem.getBoundingClientRect();
- return (
- distance.top >= 0 &&
- distance.left >= 0 &&
- distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
- distance.right <= (window.innerWidth || document.documentElement.clientWidth)
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement