• Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React library for scroll and mousemove parallax effect ✨ Open source, production-ready

React Just Parallax

React Just Parallax

React library for scroll and mousemove parallax effect
Open source, production-ready


This repo contains the source code for React Just Parallax, source code for documentation page and source code for testing the package locally.

  • Written in TypeScript
  • Super lightweight
  • Easy to use
  • blazing fast

📦 NPM Link

📜 Examples

⚖️ License

  • React Just Parallax is MIT licensed.

✍🏻 Author

🐇 Quick start

npm install react-just-parallax
import { MouseParallax, ScrollParallax } from "react-just-parallax";

export const MyComponent = () => (
  <>
    <MouseParallax>
      <p>I'm reacting to mouse move</p>
    </MouseParallax>

    <ScrollParallax>
      <p>I'm reacting to scroll</p>
    </ScrollParallax>
  </>
);

Props for MouseParallax

Name Type Default Description
strength number 0.14 Parallax offset multiplier. Moving mouse by 10 pixels will move element position by 10px * strength
lerpEase number 0.06 Determines how quick the interpolation between offset values occurs (the higher the quicker)
isAbsolutelyPositioned boolean false If the element you want to use parallax on is positioned absolutely, set this prop to true
zIndex number | null null Specify element's outer container z-index (useful while using isAbsolutelyPositioned prop)
shouldPause boolean true Stops element from reacting to scroll and interpolating offset if it is out of view
enableOnTouchDevice boolean false Turns on/off parallax effect on touch devices
scrollContainerRef React.MutableRefObject | null null Use when element is situated in scrollable element other than window
parallaxContainerRef React.MutableRefObject | null null By default, element reacts to mousemove on window. You can specify any other container using this prop to make element react only within given container
shouldResetPosition boolean false Resets element's position if cursor leaves window or leaves parallaxContainerRef

Props for ScrollParallax

Name Type Default Description
strength number 0.14 Parallax offset multiplier. Scrolling by 10 pixels will move element position by 10px * strength
lerpEase number 0.06 Determines how quick the interpolation between offset values occurs (the higher the quicker)
isAbsolutelyPositioned boolean false If the element you want to use parallax on is positioned absolutely, set this prop to true
zIndex number | null null Specify element's outer container z-index (useful while using isAbsolutelyPositioned prop)
shouldPause boolean true Stops element from reacting to scroll and interpolating offset if it is out of view
enableOnTouchDevice boolean true Turns on/off parallax effect on touch devices
isHorizontal boolean false Enable if using horizontal scrolling
scrollContainerRef React.MutableRefObject | null null Use when element is situated in scrollable element other than window

Recalculating values on demand for ScrollParallax

It's sometimes necessary to update values such as element's position or sizes on demand, for example if the DOM structure changes.

Library can't know of this kind of changes so it is not able to handle it by itself, and that's when we need to use ScrollParallaxHandle to update them manually.

import { ScrollParallax, ScrollParallaxHandle } from "react-just-parallax";

export const MyComponent = () => {
  const [display, setDisplay] = useState(true);
  const scrollParallaxRef = useRef<ScrollParallaxHandle | null>(null);

  useEffect(() => {
    scrollParallaxRef.current?.updateValues();
  }, [display]);

  return (
    <>
      <ScrollParallax ref={scrollParallaxRef}>
        <p>I'm reacting to scroll</p>
      </ScrollParallax>

      {display && (
        <button onClick={() => setDisplay((false)}>
          Disappear me
        </button>
      )}
    </>
  );
};

More Repositories

1

creativeprojects

Personal website that features a range of interactive projects , that I've been working on 🌌 . Main technologies used are THREE.JS and 2D Context API.
TypeScript
299
star
2

creative-bay

WebGL and GLSL projects 2022 🌬
TypeScript
256
star
3

webgl-3d-engine

WebGL2 3D Engine built from scratch.
TypeScript
208
star
4

threejs-page-transition

Web application, that uses THREE.JS and NextJS for the transitions between pages 👾. I've created this project to test the possibility of merging SPA'a and awwwards-like page transitions.
TypeScript
184
star
5

3d-renderer-in-c

3D graphics renderer made from scratch using the C programming language.
C
81
star
6

book-of-shaders-playground

Web application that I've built while learning from "The Book Of Shaders" 🔮. It features most of the fragment shader concepts covered in the book and more.
GLSL
56
star
7

plain-page-transition

Transition between pages made from scratch with plain JavaScript and no external libraries
TypeScript
49
star
8

raymarching-engine-visualiser

Interactive visualiser 🌠 for a 3D raymarching engine written in GLSL and computed in a fragment shader on the 2D Plane.
TypeScript
29
star
9

next-sandbox

All custom components I have made and constantly trying to improve 🚀. I use them mostly in my React applications, but all of them might be easily transfered and used with pure css and js.
TypeScript
11
star
10

team-29

Interactive game and web application with custom Backend and Frontend setup. It was a team project from Newcastle University 🎓, aiming to combat United Nations sustainable development goal 15.
TypeScript
8
star
11

awwwards-3d-course

JavaScript
6
star
12

fastify-prisma-postgresql

REST app built with Fastify, Prisma & TypeScript
TypeScript
3
star
13

learning-c

C
2
star
14

opengl-learning

Repo used to learn from learnopengl.com
C
2
star
15

2d-physics-engine

2D Physics engine built from scratch in C++.
C++
2
star
16

expo-base

TypeScript
1
star
17

next-typescript-frontend

TypeScript
1
star
18

subdir-heroku-buildpack

Shell
1
star
19

express-typescript-backend

Express backend application with OAuth2 ✨ stategies provided with PassportJS and secure design patterns.
TypeScript
1
star
20

eleventy-esbuild-test

SCSS
1
star