Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save snowman-repos/8840302 to your computer and use it in GitHub Desktop.
Save snowman-repos/8840302 to your computer and use it in GitHub Desktop.
Determine if an Element is in the Viewport
# Determine if an element is in the visible viewport
isInViewport = (element) ->
rect = element.getBoundingClientRect()
html = document.documentElement
rect.top >= 0 and rect.left >= 0 and rect.bottom <= (window.innerHeight or html.clientHeight) and rect.right <= (window.innerWidth or html.clientWidth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment