Skip to content

Instantly share code, notes, and snippets.

@ivoputzer
Last active September 8, 2019 22:16
Show Gist options
  • Save ivoputzer/351612cddc8c7e497712 to your computer and use it in GitHub Desktop.
Save ivoputzer/351612cddc8c7e497712 to your computer and use it in GitHub Desktop.
scrolledIntoView.js
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
}
@papayaah
Copy link

papayaah commented Aug 9, 2017

thanks for this, works perfectly! even in both mobile landscape and portrait views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment