Last active
October 14, 2015 14:19
-
-
Save Loiree/308571848a22436c70c6 to your computer and use it in GitHub Desktop.
Scroll to Anchor 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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