Skip to content

Instantly share code, notes, and snippets.

@jzntam
Last active December 28, 2015 23:59
Show Gist options
  • Save jzntam/eeafacd50c6ecadca1e2 to your computer and use it in GitHub Desktop.
Save jzntam/eeafacd50c6ecadca1e2 to your computer and use it in GitHub Desktop.
How to use parallax

Example: https://github.com/jzntam/fundamentals-dec-2014-exam/blob/master/views/cool.erb

Place parallax.min.js into the app/assets/javascripts

In the view you are working on...

Because we are using rails, you must use the <%= asset_path 'whatever-image.jpg' %> tag when you are in an element.

<div class="parallax-window" data-parallax="scroll" data-image-src="<%= asset_path 'image.jpg' %>">
  <div class="hello-container">
    <p>content....</p>
  </div>
</div>

Add application.scss

.hello-container {
  height: 600px;
  position: relative;
  margin: 0 auto;
}

Add it in again but with a different image...

<div class="parallax-window" data-parallax="scroll" data-image-src="<%= asset_path 'someotherimage.jpg' %>">
  <div class="hello-container">
    <p>content....</p>
  </div>
</div>

ALL DONE! you can play around with the window sizes as well to change the effects.

MOAR options here http://pixelcog.github.io/parallax.js/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment