Last active
September 21, 2019 18:08
-
-
Save mciastek/982581ca2c439e2395788533d8aad34e to your computer and use it in GitHub Desktop.
This file contains 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
const isInViewport = ({ top, height, windowHeight }) => { | |
const scroll = window.scrollY || window.pageYOffset; | |
const boundsTop = top + scroll; | |
const viewport = { | |
top: scroll, | |
bottom: scroll + windowHeight, | |
}; | |
const bounds = { | |
top: boundsTop, | |
bottom: boundsTop + height, | |
}; | |
return (bounds.bottom >= viewport.top && bounds.bottom <= viewport.bottom) | |
|| (bounds.top <= viewport.bottom && bounds.top >= viewport.top); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment