Convert Figma logo to code with AI

dixonandmoe logorellax

Lightweight, vanilla javascript parallax library

7,064
878
7,064
75

Top Related Projects

10,422

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

The javascript library for magical scroll interactions.

16,455

Parallax Engine that reacts to the orientation of a smart device

Parallax scrolling for modern browsers

Animate elements as they scroll into view.

3,593

🚀 Performance focused, lightweight scroll animation library 🚀

Quick Overview

Rellax is a lightweight, vanilla JavaScript parallax library that adds a smooth parallax scrolling effect to websites. It's designed to be easy to use, with no dependencies, and works on both desktop and mobile devices.

Pros

  • Lightweight and dependency-free
  • Easy to implement and customize
  • Supports horizontal parallax scrolling
  • Works well on mobile devices

Cons

  • Limited advanced features compared to more complex parallax libraries
  • May not be suitable for highly complex parallax designs
  • Performance can be affected if overused on a single page

Code Examples

Basic usage:

<div class="rellax">
  I'm a slow-moving element
</div>

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

Custom speed and vertical offset:

<div class="rellax" data-rellax-speed="2" data-rellax-percentage="0.5">
  I move faster and have a custom vertical offset
</div>

Horizontal parallax:

<div class="rellax" data-rellax-horizontal-speed="2" data-rellax-vertical-speed="-1">
  I move horizontally and vertically
</div>

Getting Started

  1. Include the Rellax script in your HTML:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/rellax/1.12.1/rellax.min.js"></script>
    
  2. Add the rellax class to elements you want to animate:

    <div class="rellax">
      I'm a parallax element
    </div>
    
  3. Initialize Rellax in your JavaScript:

    var rellax = new Rellax('.rellax');
    
  4. Customize speed and behavior using data attributes:

    <div class="rellax" data-rellax-speed="-2">
      I move slower in the opposite direction
    </div>
    

Competitor Comparisons

10,422

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

Pros of lax.js

  • More versatile with a wider range of animation effects
  • Supports mobile-friendly touch events
  • Offers presets for quick implementation of common effects

Cons of lax.js

  • Slightly larger file size
  • May have a steeper learning curve for complex animations
  • Requires more setup for basic parallax effects

Code Comparison

lax.js:

lax.init()
lax.addDriver('scrollY', function () {
  return window.scrollY
})
lax.addElements('.selector', {
  scrollY: {
    translateY: [
      ["elInY", "elOutY"],
      [0, 100],
    ]
  }
})

Rellax:

var rellax = new Rellax('.selector', {
  speed: -2,
  center: false,
  wrapper: null,
  round: true,
  vertical: true,
  horizontal: false
});

Both libraries offer smooth parallax scrolling effects, but lax.js provides more customization options and animation types. Rellax is simpler to set up for basic parallax effects, while lax.js requires more configuration but offers greater flexibility. lax.js supports touch events, making it more suitable for mobile devices. However, its increased functionality comes at the cost of a larger file size and potentially more complex implementation for advanced features.

The javascript library for magical scroll interactions.

Pros of ScrollMagic

  • More feature-rich, offering complex animations and scene management
  • Supports pin and progress-based animations
  • Integrates well with other animation libraries like GSAP

Cons of ScrollMagic

  • Steeper learning curve due to more complex API
  • Larger file size, which may impact page load times
  • Requires more setup and configuration for basic effects

Code Comparison

ScrollMagic:

var controller = new ScrollMagic.Controller();
var scene = new ScrollMagic.Scene({
    triggerElement: "#trigger",
    duration: 300
})
.setTween("#animate", {scale: 2})
.addTo(controller);

Rellax:

var rellax = new Rellax('.rellax', {
    speed: -2,
    center: true,
    wrapper: null,
    round: true,
    vertical: true,
    horizontal: false
});

ScrollMagic offers more control over animations with scene-based management, while Rellax provides a simpler API for parallax effects. ScrollMagic is better suited for complex, timeline-based animations, whereas Rellax excels in creating lightweight parallax scrolling effects with minimal setup.

16,455

Parallax Engine that reacts to the orientation of a smart device

Pros of Parallax

  • More feature-rich, offering various parallax effects and options
  • Supports mobile devices with gyroscope-based parallax
  • Includes a scene graph for complex layouts and animations

Cons of Parallax

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API
  • Less actively maintained (last update in 2019)

Code Comparison

Rellax:

var rellax = new Rellax('.rellax', {
  speed: -2,
  center: false,
  wrapper: null,
  round: true,
  vertical: true,
  horizontal: false
});

Parallax:

var scene = document.getElementById('scene');
var parallaxInstance = new Parallax(scene, {
  relativeInput: true,
  clipRelativeInput: false,
  hoverOnly: true,
  inputElement: document.getElementById('input')
});

Both libraries offer simple initialization, but Parallax provides more options for complex setups. Rellax focuses on vertical scrolling parallax, while Parallax offers multi-directional effects and device orientation support.

Rellax is lighter and easier to implement for basic parallax scrolling, making it suitable for simpler projects. Parallax is more powerful but requires more setup, better suited for complex, interactive websites with diverse parallax effects.

Parallax scrolling for modern browsers

Pros of Jarallax

  • More feature-rich, offering video backgrounds and advanced parallax effects
  • Better browser compatibility, including older versions of Internet Explorer
  • Supports both vertical and horizontal parallax scrolling

Cons of Jarallax

  • Larger file size due to additional features
  • Slightly more complex setup and configuration
  • May have a higher performance impact on slower devices

Code Comparison

Rellax initialization:

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

Jarallax initialization:

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2
});

Both libraries offer simple initialization, but Jarallax provides more options for customization out of the box. Rellax focuses on simplicity and ease of use, while Jarallax offers a wider range of features and configuration options.

Rellax is lightweight and straightforward, making it ideal for simple parallax effects. Jarallax, on the other hand, is more suitable for complex projects requiring advanced parallax functionality and broader browser support.

Choose Rellax for quick, lightweight implementations, and Jarallax for more feature-rich, customizable parallax experiences.

Animate elements as they scroll into view.

Pros of ScrollReveal

  • More feature-rich, offering a wider range of animation options
  • Better documentation and examples, making it easier for developers to implement
  • Supports both JavaScript and CSS-based animations for better performance

Cons of ScrollReveal

  • Larger file size, which may impact page load times
  • Steeper learning curve due to more configuration options
  • May be overkill for simple parallax effects

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.headline', {
    delay: 200,
    distance: '50px',
    origin: 'bottom',
    duration: 1000
});

Rellax:

var rellax = new Rellax('.rellax', {
    speed: -2,
    center: false,
    wrapper: null,
    round: true
});

ScrollReveal offers more granular control over animations, while Rellax focuses specifically on parallax effects with simpler configuration. ScrollReveal's code allows for more customization of animation properties, whereas Rellax's implementation is more straightforward for basic parallax scrolling.

Both libraries have their strengths, with ScrollReveal being more versatile for various scroll-based animations and Rellax excelling in lightweight, easy-to-implement parallax effects. The choice between them depends on the specific needs of the project and the desired complexity of scroll animations.

3,593

🚀 Performance focused, lightweight scroll animation library 🚀

Pros of Sal

  • More advanced animation options, including enter/exit animations and easing functions
  • Supports both scroll-based and intersection observer-based animations
  • Offers a wider range of customization options for animations

Cons of Sal

  • Slightly larger file size compared to Rellax
  • May have a steeper learning curve due to more complex configuration options
  • Less focused on parallax effects specifically

Code Comparison

Rellax:

var rellax = new Rellax('.rellax', {
  speed: -2,
  center: false,
  wrapper: null,
  round: true,
  vertical: true,
  horizontal: false
});

Sal:

sal({
  threshold: 0.5,
  once: false,
  animateClassName: 'sal-animate',
  disabledClassName: 'sal-disabled',
  enterEventName: 'sal:in',
  exitEventName: 'sal:out',
});

Both libraries offer easy-to-use initialization, but Sal provides more configuration options out of the box. Rellax focuses primarily on parallax scrolling effects, while Sal offers a broader range of scroll-based animations. Sal's code demonstrates its flexibility in handling various animation scenarios, whereas Rellax's code highlights its simplicity for parallax effects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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

Using npm

npm install rellax --save

Using yarn

yarn add rellax

CDN

<script src="https://cdn.jsdelivr.net/gh/dixonandmoe/rellax@master/rellax.min.js"></script>

Download Locally

if you're old school like us download and insert rellax.min.js in your html

<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="https://cdn.jsdelivr.net/gh/dixonandmoe/rellax@master/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: moe@dixonandmoe.com

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

NPM DownloadsLast 30 Days