Skip to content

Instantly share code, notes, and snippets.

@genoma
Created September 10, 2014 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save genoma/d075e6e36580e883880c to your computer and use it in GitHub Desktop.
Save genoma/d075e6e36580e883880c to your computer and use it in GitHub Desktop.
Element is on view, return false, true
isScrolledIntoView = (elem) ->
docViewTop = $(window).scrollTop()
docViewBottom = docViewTop + $(window).height()
elemTop = $(elem).offset().top
elemBottom = elemTop + $(elem).height()
(elemBottom - 200 < docViewBottom) and (elemBottom + $(elem).height() > docViewBottom )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment