Last active
September 8, 2019 22:16
-
-
Save ivoputzer/351612cddc8c7e497712 to your computer and use it in GitHub Desktop.
scrolledIntoView.js
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
function scrolledIntoView(element) { | |
var rect = element.getBoundingClientRect() | |
, h = (window.innerHeight || document.documentElement.clientHeight) | |
, w = (window.innerWidth || document.documentElement.clientWidth) | |
, verticalVisibility = (rect.top <= h) && ((rect.top + rect.height) >= 0) | |
, horizontalVisibility = (rect.left <= w) && ((rect.left + rect.width) >= 0) | |
return verticalVisibility && horizontalVisibility | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this, works perfectly! even in both mobile landscape and portrait views.