
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
react-scroll-parallax
Advanced tools
Provides a React component and single global passive scroll listener to add vertical scrolling based offsets to elements based on their position in the viewport. Works with server-side rendering and universal React apps.
🔗 Example
⚠️ Warning: This is a beta pre-release
npm i --save react-scroll-parallax@beta
Import ParallaxController on the client side and call ParallaxController.init() to create the global ParallaxController which will handle updating all parallax elements on scroll.
import { ParallaxController } from 'react-scroll-parallax';
ParallaxController.init();
Import the Parallax component...
import { Parallax } from 'react-scroll-parallax';
... then use it like so:
<Parallax
className="custom-class"
offsetYMax={20}
offsetYMin={-20}
slowerScrollRate
tag="figure"
>
<img src="/image" />
</Parallax>
The following are all props that can be passed to the React <Parallax /> component:
className
StringOptionally pass additional class names to be added to the outer parallax element.
disabled
BooleanfalseDetermines if the component will have parallax offsets applied. If true parallax styles are completely removed from the element and it is no longer updated.
offsetXMax
Number or String0Maximum x offset in % or px. If no unit is passed percent is assumed. Percent is based on the elements width.
offsetXMin
Number or String0Minimum x offset in % or px. If no unit is passed percent is assumed. Percent is based on the elements width.
offsetYMax
Number or String0Maximum y offset in % or px. If no unit is passed percent is assumed. Percent is based on the elements height.
offsetYMin
Number or String0Minimum y offset in % or px. If no unit is passed percent is assumed. Percent is based on the elements height.
slowerScrollRate
BooleanfalseDetermines whether the scroll rate of the parallax component will move faster or slower than the default rate of scroll.
tag
StringdivOptionally pass a tag name to be applied to the outer most parallax element. For example: <Parallax tag="figure" />.
The following are public methods available on the ParallaxController global:
update()
Updates all cached attributes for parallax elements then updates their positions.
destroy()
Removes window scroll and resize listeners, resets all styles applied to parallax elements, and sets the global ParallaxController to null.
Install node modules and start webpack:
npm i
Run webpack watch:
npm run dev
Run dev server:
npm run dev-server
Run Jest tests:
npm run test
React Scroll Parallax uses a single passive scroll listener (dependent on browser support) with the minimal amount of work done on the scroll event to prevent jank (calculations that cause layout, reflow and paint are cached initially and only updated when layout changes). Request animation frame is then used to decouple the scroll handler and further reduce jank. All offsets are applied with 3D transforms to utilize the GPU and prevent paints. If you have ideas to further optimize scrolling please PR or post an issue.
PSA
It's 2017 and you probably shouldn't be building parallax sites—but if you do (like I did) and you use this package try and use it responsibly. Keeping images small and optimized, reducing the number of moving elements in view and on the page, and disabling scroll effects on mobile devices should help achieve silky smooth animations and minimize annoying visitors.
FAQs
React hooks and components to create parallax scroll effects for banners, images or any other DOM elements.
The npm package react-scroll-parallax receives a total of 41,186 weekly downloads. As such, react-scroll-parallax popularity was classified as popular.
We found that react-scroll-parallax demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.