Skip to content

Instantly share code, notes, and snippets.

@nickjacob
Created March 30, 2015 15:50
Show Gist options
  • Save nickjacob/a10d6f7d959f67c157c2 to your computer and use it in GitHub Desktop.
Save nickjacob/a10d6f7d959f67c157c2 to your computer and use it in GitHub Desktop.
fake event for on iphone scroll end
# this should be x-browser check
_raf = window.requestAnimationFrame
isScrolling = (fn) ->
pageY = window.pageYOffset
_checker = ->
unless (fn(pageY != window.pageYOffset) is false)
pageY = window.pageYOffset
_raf(_checker)
_raf(_checker)
return _checker
$window = $(window)
onscrollend = (handler) ->
timeout = null
$window.on 'scroll.end', ->
# throttle the function since we know
# that scroll won't end while we're scrolling.
# this will introduce delay so could be removed
clearTimeout(timeout)
timeout = setTimeout(->
isScrolling((changed) ->
return if changed
# push to bottom of the stack
# to be sure that scroll rendering has finished
setTimeout(handler, 0)
$window.off 'scroll.end'
return false
)
, 100)
# usage
onscrollend = ->
$('#element').show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment