Created
November 3, 2017 09:24
-
-
Save rabarbara/8ff849d40a55bdfe24b4d68d942fa62e to your computer and use it in GitHub Desktop.
Did the element scroll into view?
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
| //https://stackoverflow.com/a/22480938/5400353 | |
| function isScrolledIntoView(el) { | |
| var elemTop = el.getBoundingClientRect().top; | |
| var elemBottom = el.getBoundingClientRect().bottom; | |
| // Only completely visible elements return true: | |
| //var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight); | |
| // Partially visible elements return true: | |
| isVisible = elemTop < window.innerHeight && elemBottom >= 0; | |
| return isVisible; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment