RELLAXJS

Lightweight

Vanilla Javascript

Parallax Library

San Francisco
California

Incorporated—
1850

37°47′N 122°25′W
68°

Getting Started!

npm install rellax --save

or if you're old school like us, download and insert rellax.min.js file in your project folder.

JavaScript (`accepts any class name`)

var rellax = new Rellax('.rellax');

Basic Markup (Default Speed: -2)

<div class="rellax">
  I’m slow and smooth
</div>

Optional Speed (-10 to +10)

<div class="rellax" data-rellax-speed="-3">
  I’m slow and smooth
</div>

<div class="rellax" data-rellax-speed="7">
  I’m super fast!!
</div>

<div class="rellax" data-rellax-speed="-5">
  I’m extra slow and smooth
</div>

Speed

Use the data-rellax-speed attribute to set the speed of a .rellax element to something other than the default value (which is -2). A negative value will make it move slower than regular scrolling, and a positive value will make it move faster. We recommend keeping the speed between -10 and +10.

Responsive Speed

Use responsive speed attributes for breakpoint levels that require a different speed. Defaults to the data-rellax-speed setting in unspecified breakpoints.

<div
  class="rellax"
  data-rellax-speed="7"
  data-rellax-xs-speed="-5"
  data-rellax-mobile-speed="3"
  data-rellax-tablet-speed="-8"
  data-rellax-desktop-speed="1">
    I parallax at all different speeds depending on your screen width.
</div>

Pass an array of breakpoints. Each breakpoint value represents the resolution for mobile, tablet, desktop respectively. Checkout the responsiveness of the demo.

<script>
  //default JS Setting
  var rellax = new Rellax('.rellax', {
    breakpoints:[576, 768, 1201]
  }
);
</script>

Centering

After some fantastic work from @p-realinho, we just released the ability to center parallax elements in your viewport! We'll be building a nice demo website, but for now check out the tests folder for several examples of how it works via our tests folder on GitHub.


There's two ways to implement centering, either on specific elements or as a global option.

<div class="rellax" data-rellax-percentage="0.5">
  I’m that default chill speed of "-2" and "centered"
</div>

<div class="rellax" data-rellax-speed="7"
  data-rellax-percentage="0.5">
  I’m super fast!! And super centered!!
</div>

<div class="rellax" data-rellax-speed="-4"
  data-rellax-percentage="0.5">
  I’m extra slow and smooth, and hella centered.
</div>
<script>
  //default JS Setting
  var rellax = new Rellax('.rellax', {
    center:true
  }
);
</script>

Z-Index

If you want to sort your elements properly in the Z space, you can use the
data-rellax-zindex property.


<div class="rellax">
  I’m that default chill speed of "-2" and default   z-index of 0
</div>

<div class="rellax" data-rellax-speed="7"
  data-rellax-zindex="5">
  I’m super fast!! And on top of the previous   element, I'm z-index 5!!
</div>

Horizontal Parallax

Horizontal parallax is disabled by default. You can enable it by passing
horizontal: true in the settings block. This feature is intended for panoramic style websites, where users scroll horizontally instead of vertically. Note that this can work together at the same time with the default vertical parallax. If you do not want this, pass vertical: false.


<script>
  //Enable Horizontal Parallax Scrolling
  var rellax = new Rellax('.rellax', {
    horizontal:true

    //Disable vertical Parallax Scrolling     vertical:false
  }
);
</script>

Custom Wrapper

By default, the position of parallax elements is determined via the scroll position of the body. Passing in the wrapper property in the settings block will tell Rellax to watch that element instead.


<script>
  //Set wrapper to .custom-element instead of the body
  var rellax = new Rellax('.rellax', {
    wrapper:'.custom-element'
  }
);
</script>

Target Node

Instead of using a className you can use a node, handy when using React and you want to use refs instead of className


<div ref = {ref => { this.rellaxRef = ref}}>
  I’m that default chill speed of "-2"
</div>

<script>
  var rellax = new Rellax(this.rellaxRef);
</script>

Refresh

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax');

  // Destroy and create again parallax with previous settings
  rellax.refresh();
</script>

Destroy

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax');

  // End Rellax and reset parallax elements to their original positions
  rellax.destroy();
</script>

SERIOUSLY, WHY?!

Come on, how boring is the internet without gratuitous javascript? We made this library since too many github repos are abandoned (RIP skrollr) or feature creepy. You got some beef or caught us slippin on unit tests, send rants and 10mb gifs to moe@dixonandmoe.com

BUT ACTUALLY

We've benefitted so much from open source projects and developers that we're actively trying to give back and we're starting by releasing our own quirky js code.