3.1.16 • Published 1 year ago

react-just-parallax v3.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Just Parallax is an open source, production-ready library that's designed for all creative developers and more.

  • 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

NameTypeDefaultDescription
strengthnumber0.14Parallax offset multiplier. Moving mouse by 10 pixels will move element position by 10px * strength
lerpEasenumber0.06Determines how quick the interpolation between offset values occurs (the higher the quicker)
isAbsolutelyPositionedbooleanfalseIf the element you want to use parallax on is positioned absolutely, set this prop to true
zIndexnumber | nullnullSpecify element's outer container z-index (useful while using isAbsolutelyPositioned prop)
shouldPausebooleantrueStops element from reacting to scroll and interpolating offset if it is out of view
enableOnTouchDevicebooleanfalseTurns on/off parallax effect on touch devices
scrollContainerRefReact.MutableRefObject | nullnullUse when element is situated in scrollable element other than window
parallaxContainerRefReact.MutableRefObject | nullnullBy default, element reacts to mousemove on window. You can specify any other container using this prop to make element react only within given container
shouldResetPositionbooleanfalseResets element's position if cursor leaves window or leaves parallaxContainerRef

Props for ScrollParallax

NameTypeDefaultDescription
strengthnumber0.14Parallax offset multiplier. Scrolling by 10 pixels will move element position by 10px * strength
lerpEasenumber0.06Determines how quick the interpolation between offset values occurs (the higher the quicker)
isAbsolutelyPositionedbooleanfalseIf the element you want to use parallax on is positioned absolutely, set this prop to true
zIndexnumber | nullnullSpecify element's outer container z-index (useful while using isAbsolutelyPositioned prop)
shouldPausebooleantrueStops element from reacting to scroll and interpolating offset if it is out of view
enableOnTouchDevicebooleantrueTurns on/off parallax effect on touch devices
isHorizontalbooleanfalseEnable if using horizontal scrolling
scrollContainerRefReact.MutableRefObject | nullnullUse 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>
      )}
    </>
  );
};
3.1.16

1 year ago

3.1.15

1 year ago

3.1.14

2 years ago

3.1.13

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.10

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago