Lightweight, vanilla javascript parallax library

Related tags

Scroll rellax
Overview

RELLAX

NPM Package Minified Size Gzipped Size

Rellax is a buttery smooth, super lightweight, vanilla javascript parallax library. Update: Rellax now works on mobile (v1.0.0).

Getting Started

npm install rellax --save or if you're old school like us download and insert rellax.min.js

<div class="rellax">
  I’m that default chill speed of "-2"
</div>
<div class="rellax" data-rellax-speed="7">
  I’m super fast!!
</div>
<div class="rellax" data-rellax-speed="-4">
  I’m extra slow and smooth
</div>

<script src="rellax.min.js"></script>
<script>
  // Accepts any class name
  var rellax = new Rellax('.rellax');
</script>
<script>
  // Also can pass in optional settings block
  var rellax = new Rellax('.rellax', {
    speed: -2,
    center: false,
    wrapper: null,
    round: true,
    vertical: true,
    horizontal: false
  });
</script>

Features

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>
  // This is the default 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.

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

  1. Element-wise Centering

  • Add the data-rellax-percentage="0.5" to a specific html element
<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>
  1. Global Centering

  • To activate the center feature in your whole html, add the code your <script> tag or JS file:
<script>
  // Center all the things!
  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 in the settings block.

<script>
  // Adding horizantal parallax scrolling
  var rellax = new Rellax('.rellax', {
    // Activate horizantal scrolling
    // Turned off by default
    horizontal: true
    //Deactivate vertical 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 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>

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>

Callback

<script>
  // Start Rellax
  var rellax = new Rellax('.rellax-blur-card', {
    callback: function(positions) {
      // callback every position change
      console.log(positions);
    }
  });
</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>

var rellax = new Rellax(this.rellaxRef)

In the Wild

If you're using Rellax in production, we'd love to list you here! Let us know: [email protected]

Development

In the spirit of lightweight javascript, the build processes (thus far) is lightweight also.

  1. Open demo.html
  2. Make code changes and refresh browser
  3. Once feature is finished or bug fixed, use jshint to lint code
  4. Fix lint issues then use Google Closure Compiler to minify
  5. 🍻

Changelog

  • 1.7.1: Remove animation on destory PR
  • 1.7.0: Scroll position set relative to the wrapper PR
Comments
  • Issues regarding smoothness of parallax effect

    Issues regarding smoothness of parallax effect

    Hi there!

    First of all, thanks for your work. This is a really good library!

    I encountered some issues regarding the smoothness of the parallax effect. The elements which have the parallax effect attached are jumping around a bit and do not move smoothly.

    After trying out some things I believe that the behavior somehow depends on the speed of the element you declare with the data-rellax-speed attribute since elements with speed -7 are for example jumping around much more than elements with speed 7. So, it seems like the lower the speed, the worse the problem.

    In order to illustrate the problem a bit, I have created a Pen which has four elements with different speeds. Furthermore, I have recorded a short clip to better clarify what I mean with "jumping around".

    Link to the Pen: https://codepen.io/jr-cologne/pen/jagaMK Link to the video: https://streamable.com/rxghi

    I tested the whole thing in the following browsers:

    • Chrome version 63.0.3239.84 64 bit (working fine)
    • Chrome Mobile version 63.0.3239.107 (affected)
    • Firefox 57.0.2 64 bit (a bit worse than Chrome, but still reasonable)
    • Edge 16.16299 (definitely affected)
    • IE 11.64.16299.0 (same as Edge)

    Thank you in advance for any efforts you put into this issue!

    Best regards from Germany, @jr-cologne

    opened by jr-cologne 16
  • Added data-rellax-percentage.

    Added data-rellax-percentage.

    Added the attribute data-rellax-percentage, to make it possible to easily offset elements (relatively to their initial position). This avoids elements further down the page to be too far away from their initial position when you scroll past them. For example, if you set the data-rellax-percentage to 0.5, the element will be in it's initial position when it's scrolled into the viewport's center.

    opened by p-realinho 16
  • wrapper problem

    wrapper problem

    First of all, thank you for publishing this wonderful plugin. I am looking for ways to parallax within a certain section. I read the document and wrote it as it was written, but it does not move. I want to move only div in body, but what should I do?

    It doesn't work...

    opened by junhee0122 11
  • Option to disable on mobile?

    Option to disable on mobile?

    Hi. Love this library on desktop. But in general I hate parallax on mobile devices due to wierd browser address bar behavior. Is there any tips how to disable rellax on mobile? I could detect mobile devices, but what next?

    enhancement 
    opened by hackuun 10
  • Add a new boolean option, relativeToWrapper.

    Add a new boolean option, relativeToWrapper.

    This addition originates from the need to let movement be relative to a wrapper, rather than scroll position of a wrapper or the scroll position of the window. We'll use the wrappers vertical offset, and subtract it from the scrollposition, to enable an effect, that feels like the element is relative to its wrapper instead.

    Simply a boolean, telling us whether or not it should be relative to the container selected in the wrapper option.

    opened by MadsMadsDk 9
  • Parallax effect isn't working

    Parallax effect isn't working

    Hi,

    I recently did find Rellax and wanted to use it on my website. I did the following:

    1. Link the script at the bottom of my page like this: <script src="js/rellax.js"></script> Yes I don't use the minified version for the development process.
    2. I added the .rellax class to all my desired elements
    3. I added this code at the bottom of may page aswell: <script> var rellax = new Rellax();</script>
    4. I refreshed the page to see the result, but none of the elements are moving. The style get's added but stays at transform: translate3d(0px, 0px, 0px); even when scrolling.

    I am using the latest version of your script and Chrome version 63.0.3239.132.

    So I hope you can help me fixing this problem or maybe I dicovered a bug.

    opened by Techassi 8
  • Request to implement delay on some elements

    Request to implement delay on some elements

    How feasible is it to implement a 'delay' method so it would be possible to keep some elements in place for specified amount of time before they get animated (follow the scroll)? Primary use is for the elements that are located "above the fold". Looking for a way to start parallax scroll with elements animated one by one.

    opened by iapparatus 8
  • Parallax effect only for elements in viewport?

    Parallax effect only for elements in viewport?

    I am having a newsfeed with images+titles below them like Flipboard. I am applying the parallax effect to the images just like Flipboard app. And after trying many plugins, rellax is doing the best job for all its simplicity and lightweight.

    But am wondering how to make the parallax effect run only when elements come into viewport. This will be helpful to make the effect more pronounced as right now at the default of -2 speed and 0.5 rellax percentage, the images in the bottom of the feed, when they come into the viewport, are way off from their respective titles.

    opened by envieme 8
  • Added wrapper option

    Added wrapper option

    Needed option in #26

    Example of use:

    var rellax = new Rellax('.rellax', {
        wrapper: document.querySelector('.wrapper') // DOMElement
    });
    

    or

    var rellax = new Rellax('.rellax', {
        wrapper: '.wrapper' // selector
    });
    
    opened by kajetan-nobel 8
  • Set botttom boundary on rellax

    Set botttom boundary on rellax

    By setting the data-rellax-boundary to a valid parent element of the '.rellax', you can stop an element from rellaxing at a certain point. This is useful if you don't want the element to overlay anymore.

    opened by jacobraccuia 7
  • How to get almost no movement?

    How to get almost no movement?

    I am trying to get an object to nearly don't move at all. How can achieve this? Using data-rellax-speed="-10" data-rellax-percentage="0" gave me the best result, but is there another, cleaner way to get even less movement?

    As far as I understood it values above 0 mean the element is moving faster than the "default" speed, while values below 0 lead to a slower than "normal" speed movement, but correct me if I'm wrong here.

    Be aware of the fact that I am using position: absolute; for every Element.

    I've attached an archive with the project in it so one can get a better understanding of my situation web.zip

    opened by WaldemarLehner 7
  • Problem when used on the same page as JS accordion

    Problem when used on the same page as JS accordion

    Hi,

    I have an accordion that opens and closes divs on click. When they are all open, the rellax content in a lower section gets pushed out of its wrapper in overlaps other content.

    opened by hbgreg 0
  • Lead by view port

    Lead by view port

    Enumerating changes in the rellax.js file:

    1. Line 93 - leadByViewPOrt new configurable attribute for the initialization action.
    2. Line 402 - New isInViewPort() function to check targeted element position according to ViewPort.
    3. Line 420 - New conditional added to allow animation according to leadByViewPort attribute value.
    opened by cvillalobos 1
  • How to make rellax positions

    How to make rellax positions "predictable"?

    When relax items are on the very top of the page their position is predictable (https://codepen.io/iosystems/pen/VwrVeOV): the three boxes start in the middle of the container.

    Example 1

    On the contrary, when there is content above the container, rellax items positions is unpredictable (https://codepen.io/iosystems/pen/rNYQeQZ): box 1 and 3 are already outside their container.

    Question is: is there any way to say "start in the original position, despite the fact that there is content above it"?

    pen2

    opened by gremo 1
  • relativeToWrapper bugfix

    relativeToWrapper bugfix

    Added a condition to make sure scroll event listeners are not being applied to the wrapper element if relativeToWrapper is true. This fixes issue #170 .

    opened by jakobwiens7 3
  • Callbacks and doing things with them

    Callbacks and doing things with them

    Has anyone been able to use the callback to change anything outside of positions? It seems like it's not doing anything other than bringing back X & Y coordinates.

    Examples welcomed here

    opened by yratof 1
Simple and tiny JavaScript library that adds parallax animations on any images

simpleParallax.js simpleParallax.js is a very simple and tiny Vanilla JS library that adds parallax animations on any images. Where it may be laboriou

Geoffrey 1.5k Jan 3, 2023
Parallax Engine that reacts to the orientation of a smart device

Parallax Engine that reacts to the orientation of a smart device. Where no gyroscope or motion detection hardware is available, the position of the cu

Matthew Wagerfield 16k Jan 8, 2023
Stellar.js - Parallax scrolling made easy

Stellar.js PLEASE NOTE: This project is no longer maintained. If parallax scrolling is something you care about, please apply to become a contributor

Mark Dalgleish 4.6k Dec 10, 2022
jQuery plugin for creating interactive parallax effect

jquery.parallax What does jquery.parallax do? jquery.parallax turns nodes into absolutely positioned layers that move in response to the mouse. Depend

stephband 1.1k Nov 25, 2022
🛤 Detection of elements in viewport & smooth scrolling with parallax.

Locomotive Scroll Detection of elements in viewport & smooth scrolling with parallax effects. Installation ⚠️ Scroll-hijacking is a controversial prac

Locomotive 5.9k Dec 31, 2022
Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

lax.js Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll. >> DEMO << What's new w

Alex Fox 9.4k Dec 29, 2022
🚀 Scroll Follow Tab is a lightweight javascript library without jQuery, no dependencies.

Scroll Follow Tab is a lightweight javascript library without jQuery, no dependencies. It is used to make scrollspy effect for your menu, table of contents, etc. Only 21.7Kb.

Hieu Truong 11 Jun 20, 2022
🚀 Performance focused, lightweight scroll animation library 🚀

Sal Performance focused, lightweight (less than 2.8 kb) scroll animation library, written in vanilla JavaScript. No dependencies! Sal (Scroll Animatio

Mirek Ciastek 3.4k Dec 28, 2022
Dragscroll is a micro library for drag-n-drop scrolling style

Dragscroll is a micro JavaScript library (910 bytes minified) which enables scrolling via holding the mouse button ("drag and drop" or "click and hold" style, online demo). It has no dependencies and is written in vanilla JavaScript (which means it works anywhere).

Dmitry Prokashev 1.1k Dec 21, 2022
Customizable, Pluginable, and High-Performance JavaScript-Based Scrollbar Solution.

Smooth Scrollbar Customizable, Flexible, and High Performance Scrollbars! Installation ⚠️ DO NOT use custom scrollbars unless you know what you are do

Daofeng Wu 3k Jan 1, 2023
Scroll-stash - A JavaScript plugin to help preserve an element's scroll position.

scroll-stash A JavaScript plugin to help preserve an element's scroll position. CodePen Example Installation npm install scroll-stash JavaScript Impo

Sebastian Nitu 5 Sep 5, 2022
Cubic-bezier implementation for your JavaScript animation easings – MIT License

BezierEasing provides Cubic Bezier Curve easing which generalizes easing functions (ease-in, ease-out, ease-in-out, ...any other custom curve) exactly like in CSS Transitions.

@greweb 1.6k Dec 27, 2022
Slickscroll - A Lightweight JavaScript library for quick and painless momentum & parallax scrolling effects.

Slickscroll is a JavaScript library that makes momentum & parallax scrolling quick and painless View Demo: slickscroll.musabhassan.com Momentum Scroll

Musab Hassan 33 Dec 28, 2022
Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Erik Engervall 91 Dec 16, 2022
Simple fixed background parallax effect in vanilla js.

Simple Parallax Simple fixed background parallax effect in vanilla js. See demo on Codepen. JS Initialise the plugin. The first argument identifies th

null 6 Jun 27, 2022
Stand-alone parallax scrolling library for mobile (Android + iOS) and desktop. No jQuery. Just plain JavaScript (and some love).

Please note: skrollr hasn't been under active development since about September 2014 (check out the contributions graphs on https://github.com/Prinzho

Alexander Prinzhorn 18.6k Jan 3, 2023
Simple and tiny JavaScript library that adds parallax animations on any images

simpleParallax.js simpleParallax.js is a very simple and tiny Vanilla JS library that adds parallax animations on any images. Where it may be laboriou

Geoffrey 1.5k Jan 3, 2023
Simple JavaScript Library to add parallax image to background-image

Backpax Simple JavaScript Library to add parallax image to background-image Install $ npm install backpax --save Demo Demo page is here Usage If you

appleple 13 Oct 12, 2022
Parallax Engine that reacts to the orientation of a smart device

Parallax Engine that reacts to the orientation of a smart device. Where no gyroscope or motion detection hardware is available, the position of the cu

Matthew Wagerfield 16k Jan 8, 2023
Stellar.js - Parallax scrolling made easy

Stellar.js PLEASE NOTE: This project is no longer maintained. If parallax scrolling is something you care about, please apply to become a contributor

Mark Dalgleish 4.6k Dec 10, 2022