Skip to content

Instantly share code, notes, and snippets.

@genoma
Created September 10, 2014 14:23
Show Gist options
  • 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