Created
October 11, 2019 06:41
-
-
Save lovetingyuan/99d9e2602acdf44ec18d26023968513d to your computer and use it in GitHub Desktop.
isInViewport.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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) | |
); | |
}; | |
// from : https://vanillajstoolkit.com/helpers/isinviewport/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment