paradoxxxzero_butterfly/coffees/ext/smooth_scroll.coffee
2015-04-10 18:19:39 +02:00

24 lines
654 B
CoffeeScript

document.addEventListener 'DOMContentLoaded', ->
return
req = null
butterfly.native_scroll_to = (scroll=-1) ->
e = butterfly.parent
cancelAnimationFrame req if req
if scroll is -1 or (
scroll > e.scrollHeight - e.getBoundingClientRect().height)
scroll = e.scrollHeight - e.getBoundingClientRect().height
diff = scroll - e.scrollTop
return if diff is 0
step = diff / 25
scroll_step = ->
if Math.abs(e.scrollTop - scroll) < Math.abs(step)
e.scrollTop = scroll
else
e.scrollTop += step
req = requestAnimationFrame scroll_step
req = requestAnimationFrame scroll_step