Created
October 25, 2013 12:21
-
-
Save richardvenneman/7153833 to your computer and use it in GitHub Desktop.
A simple CoffeeScript parallax responsive image implementation
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
class Parallax | |
options = | |
velocity: 15 | |
constructor: -> | |
@imgs = ($ '.parralax img') | |
@offset = 0 | |
@prepareImages() | |
@bindListeners() | |
prepareImages: -> | |
for img in @imgs | |
img = ($ img) | |
img.offset = img.offset().top | |
@imgs[_i] = img | |
scrollParallax: (direction) -> | |
for img in @imgs | |
val = (img.offset - window.scrollY) / options.velocity | |
img.css(y: val) | |
bindListeners: -> | |
($ document).on 'scroll', => | |
offset = window.scrollY | |
direction = if offset > @offset then 'down' else 'up' | |
@scrollParallax direction | |
@offset = offset | |
$ -> | |
parallax = new Parallax() |
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
.illustration { | |
overflow: hidden; | |
img { | |
margin: -6% 0; | |
width: 100%; | |
height: auto; | |
} | |
} |
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
.illustration.parralax | |
= image_tag "highlight-open-bg.jpg", { retina: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment