Created
August 13, 2022 18:18
-
-
Save jgoslow/08e540f8f14b9a90a49135c182ea6d13 to your computer and use it in GitHub Desktop.
Element In View JS Helper Functions
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
/** | |
* Check if Element is in View | |
*/ | |
function elementIsVisible(el, offset) { | |
const rect = el.getBoundingClientRect(); | |
return ( | |
rect.top < window.innerHeight && rect.bottom - offset >= 0 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment