Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created May 19, 2014 13:48
Show Gist options
  • Select an option

  • Save lmartins/aef730ca112409329a7d to your computer and use it in GitHub Desktop.

Select an option

Save lmartins/aef730ca112409329a7d to your computer and use it in GitHub Desktop.
Check if an element is in Viewport
isInViewport = (el) ->
rect = el.getBoundingClientRect()
html = document.documentElement
return(
rect.top >= 0 and
rect.left >= 0 and
rect.bottom <= (window.innerHeight or html.clientHeight) and
rect.right <= (window.innerWidth or html.clientWidth)
)
isInViewport(btnEl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment