Skip to content

Instantly share code, notes, and snippets.

@Loiree
Last active October 14, 2015 14:19
Show Gist options
  • Save Loiree/308571848a22436c70c6 to your computer and use it in GitHub Desktop.
Save Loiree/308571848a22436c70c6 to your computer and use it in GitHub Desktop.
Scroll to Anchor 2.0
# ScrollToAnchor
# IE9+, iOS
# --------------------------------------------------------
# settings
# duration — продолжительность скроллинга
# timing — глобальная функция анимации
# cache
# @menu — пункт меню
# @end — до какой позиции скроллить
# scroll — функция прокрутки
# --------------------------------------------------------
ScrollToAnchor = do ->
init: ->
@settings()
@cache()
@bindeEvents()
settings: ->
@duration = 700
@timing = "ease-out"
cache: ->
@menu = document.getElementById("menu")
@end = document.getElementById("end")
bindeEvents: ->
self = @
@menu.addEventListener "click", -> self.scroll(self.end.offsetTop)
scroll: (end) ->
self = @
start = window.pageYOffset
fn = (progress) ->
pos = start * (1 - progress) + progress * end
window.scrollTo(0,pos)
AnimHandler.init(fn, self.duration, self.timing)
<button id="menu">Пункт для скорлла</button>
<section id="end">До куда скролить</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment