Created
July 26, 2013 19:59
-
-
Save leekiernan/6091799 to your computer and use it in GitHub Desktop.
Parallax scrolling
This file contains hidden or 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
| $ -> | |
| _window = $(window) | |
| scroll_div = (win, div, init=false) -> | |
| _scrolltop = win.scrollTop() | |
| _top = div.offset().top | |
| _offset = div.data("offsetY") || 0 | |
| _speed = div.data("speed") || 0 | |
| console.log "#{_scrolltop} + #{win.height()} > #{_top}" | |
| if _scrolltop + win.height() > _top and _top + div.height() > _scrolltop | |
| _pos = _scrolltop / _speed + _offset | |
| if init then _pos *= -1 | |
| else _pos += _offset | |
| div.css backgroundPosition: "50% #{_pos}px" | |
| # $( "section[data-type=\"background\"]" ).each -> | |
| $(".parallax").each -> | |
| _self = $(this) | |
| scroll_div _window, _self, true | |
| $(window).scroll -> | |
| scroll_div _window, _self, false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment