Convert Figma logo to code with AI

jscottsmith logoreact-scroll-parallax

🔮 React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.

2,858
157
2,858
6

Top Related Projects

Javascript library to create physics-based animations

10,422

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

7,064

Lightweight, vanilla javascript parallax library

16,455

Parallax Engine that reacts to the orientation of a smart device

Parallax scrolling for modern browsers

The javascript library for magical scroll interactions.

Quick Overview

React Scroll Parallax is a React library that provides components and hooks for creating parallax scrolling effects. It allows developers to easily add smooth, performant parallax animations to their React applications without the need for complex calculations or manual DOM manipulation.

Pros

  • Easy to use with React components and hooks
  • Performant, using CSS transforms for smooth animations
  • Customizable with various options for controlling parallax effects
  • Supports both vertical and horizontal scrolling

Cons

  • Limited to React applications
  • May require additional setup for complex layouts or responsive designs
  • Performance can be affected if overused or implemented incorrectly
  • Learning curve for advanced usage and customization

Code Examples

  1. Basic usage with ParallaxProvider and Parallax component:
import { ParallaxProvider, Parallax } from 'react-scroll-parallax';

function App() {
  return (
    <ParallaxProvider>
      <Parallax translateY={[-20, 20]}>
        <div>This content will move vertically</div>
      </Parallax>
    </ParallaxProvider>
  );
}
  1. Using the useParallax hook for custom effects:
import { useParallax } from 'react-scroll-parallax';

function ParallaxComponent() {
  const parallax = useParallax({
    speed: -10,
  });

  return <div ref={parallax.ref}>This will move slower than scroll</div>;
}
  1. Creating a parallax background image:
import { Parallax } from 'react-scroll-parallax';

function ParallaxBackground() {
  return (
    <Parallax translateY={[-20, 20]} style={{ overflow: 'hidden' }}>
      <img src="background.jpg" style={{ width: '100%', height: 'auto' }} />
    </Parallax>
  );
}

Getting Started

  1. Install the package:

    npm install react-scroll-parallax
    
  2. Wrap your app with ParallaxProvider:

    import { ParallaxProvider } from 'react-scroll-parallax';
    
    function App() {
      return (
        <ParallaxProvider>
          {/* Your app content */}
        </ParallaxProvider>
      );
    }
    
  3. Use Parallax components or hooks in your components:

    import { Parallax } from 'react-scroll-parallax';
    
    function MyComponent() {
      return (
        <Parallax translateY={[-50, 50]}>
          <h1>Parallax Title</h1>
        </Parallax>
      );
    }
    

Competitor Comparisons

Javascript library to create physics-based animations

Pros of dynamics.js

  • Framework-agnostic, can be used with any JavaScript project
  • Focuses on physics-based animations, offering more realistic motion
  • Smaller library size, potentially better performance for simple animations

Cons of dynamics.js

  • Less specialized for scroll-based effects compared to react-scroll-parallax
  • Requires more manual setup for scroll-triggered animations
  • Not specifically designed for React integration

Code Comparison

react-scroll-parallax:

import { Parallax } from 'react-scroll-parallax';

<Parallax y={[-20, 20]} tagOuter="figure">
  <img src="image.jpg" alt="A parallax image" />
</Parallax>

dynamics.js:

dynamics.animate(element, {
  translateY: 20
}, {
  type: dynamics.spring,
  duration: 1000,
  friction: 300
});

react-scroll-parallax is specifically designed for React applications and provides a declarative way to create scroll-based parallax effects. It offers easy integration with React components and handles scroll events automatically.

dynamics.js, on the other hand, is a more general-purpose animation library that focuses on physics-based animations. It can be used in any JavaScript project and provides more control over the animation behavior, but requires more setup for scroll-triggered effects.

10,422

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

Pros of lax.js

  • Framework-agnostic, can be used with any JavaScript project
  • Lightweight and has no dependencies
  • Offers a wide range of pre-built animations and effects

Cons of lax.js

  • Requires more manual setup and configuration
  • Less integrated with React ecosystem
  • May require more JavaScript knowledge to implement complex animations

Code Comparison

react-scroll-parallax:

import { Parallax } from 'react-scroll-parallax';

<Parallax y={[-20, 20]} tagOuter="figure">
  <img src="image.jpg" alt="A parallax image" />
</Parallax>

lax.js:

lax.addElement('.lax-element', {
  scrollY: {
    translateY: [
      ['elInY', 'elCenterY', 'elOutY'],
      [0, '-20px', '20px'],
    ]
  }
})

Both libraries offer ways to create parallax effects, but react-scroll-parallax provides a more React-centric approach with components, while lax.js uses a more traditional JavaScript method of selecting elements and applying animations. react-scroll-parallax is better suited for React projects, offering easier integration and a more declarative syntax. lax.js, on the other hand, provides more flexibility and can be used in various JavaScript environments, but may require more setup and configuration.

7,064

Lightweight, vanilla javascript parallax library

Pros of Rellax

  • Lightweight and vanilla JavaScript, no dependencies required
  • Supports horizontal parallax scrolling
  • Easy to implement with minimal setup

Cons of Rellax

  • Limited to basic parallax effects
  • Lacks advanced features like custom easing functions
  • No built-in React component support

Code Comparison

Rellax:

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

React Scroll Parallax:

import { Parallax } from 'react-scroll-parallax';

<Parallax y={[-20, 20]} tagOuter="figure">
  <img src="image.jpg" />
</Parallax>

React Scroll Parallax offers a more React-friendly approach with components and hooks, while Rellax provides a simpler vanilla JavaScript implementation. React Scroll Parallax has more advanced features and better integration with React applications, but Rellax is lighter and easier to use in non-React projects. The choice between the two depends on the specific project requirements and the developer's preference for React or vanilla JavaScript.

16,455

Parallax Engine that reacts to the orientation of a smart device

Pros of Parallax

  • Lightweight and dependency-free, making it easier to integrate into various projects
  • Supports multiple input types (mouse, accelerometer) for parallax effects
  • Offers a wider range of customization options for parallax behaviors

Cons of Parallax

  • Not specifically designed for React, requiring additional setup for React projects
  • Less active maintenance and updates compared to React Scroll Parallax
  • May require more manual configuration for complex parallax scenarios

Code Comparison

React Scroll Parallax:

import { ParallaxProvider, Parallax } from 'react-scroll-parallax';

<ParallaxProvider>
  <Parallax y={[-20, 20]} tagOuter="figure">
    <img src="image.jpg" alt="A parallax image" />
  </Parallax>
</ParallaxProvider>

Parallax:

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

Summary

React Scroll Parallax is tailored for React applications, offering easier integration and React-specific optimizations. Parallax, on the other hand, provides a more versatile solution for various project types and input methods but may require additional setup for React projects. The choice between the two depends on the specific project requirements, React usage, and desired customization level.

Parallax scrolling for modern browsers

Pros of Jarallax

  • Framework-agnostic, can be used with any JavaScript project
  • Supports video backgrounds and custom elements for parallax effects
  • Offers more customization options and advanced features

Cons of Jarallax

  • Steeper learning curve due to more complex API
  • Requires more manual setup and configuration
  • May have a larger file size due to additional features

Code Comparison

Jarallax:

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2,
    imgSrc: 'path/to/image.jpg'
});

React Scroll Parallax:

<ParallaxBanner
    layers={[{ image: 'path/to/image.jpg', speed: -20 }]}
    style={{ height: '500px' }}
/>

React Scroll Parallax is specifically designed for React applications, offering a more declarative and React-friendly API. It integrates seamlessly with React components and provides a simpler setup for basic parallax effects.

Jarallax, on the other hand, offers more flexibility and can be used in various project types. It provides advanced features like video parallax and custom element support, making it suitable for more complex parallax implementations.

The choice between the two depends on the project requirements, preferred framework, and desired level of customization.

The javascript library for magical scroll interactions.

Pros of ScrollMagic

  • More versatile, supporting various animation libraries (GSAP, Velocity.js, etc.)
  • Offers more advanced features like scene triggering and pinning elements
  • Provides a robust API for complex scroll-based animations

Cons of ScrollMagic

  • Steeper learning curve due to its extensive feature set
  • Requires more setup and configuration compared to React Scroll Parallax
  • Not specifically designed for React, may require additional integration work

Code Comparison

ScrollMagic:

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

React Scroll Parallax:

import { Parallax } from 'react-scroll-parallax';

<Parallax y={[-20, 20]}>
    <div>Parallax Element</div>
</Parallax>

ScrollMagic offers more control and flexibility for complex animations, while React Scroll Parallax provides a simpler, React-specific solution for basic parallax effects. ScrollMagic is better suited for projects requiring intricate scroll-based interactions, whereas React Scroll Parallax is ideal for React applications needing quick and easy parallax implementations.

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

React Scroll Parallax

NPM Version Latest NPM Downloads Codecov Rate on Openbase

Test and Lint Storybook Storybook

React hooks and components to create parallax scroll effects for banners, images or any other DOM elements. Utilizes Parallax Controller to add vertical or horizontal scrolling based effects to elements. Optimized to reduce jank on scroll and works with SSR and SSG rendered React apps.

If you're coming from V2, here's a migration guide.

Install

With npm

npm install react-scroll-parallax

or yarn

yarn add react-scroll-parallax

Example

Create effects with a hook:

function Component() {
  const parallax = useParallax({
    speed: -10,
  });
  return <div ref={parallax.ref} />;
}

or with a component:

function Component() {
  return (
    <Parallax speed={-10}>
      <div />
    </Parallax>
  );
}

Getting Started

Read the documentation for setup and usage instructions.

Demos

Docs: Hooks

Docs: Components

NPM DownloadsLast 30 Days