An open API service indexing awesome lists of open source software.

https://github.com/ramondeleonca/next-locomotive-scroll


https://github.com/ramondeleonca/next-locomotive-scroll

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

        

# Next Locomotive Scroll

An implementation / wrapper of [locomotive-scroll](https://locomotive-scroll.github.io) for Next.JS with built in integration with [GSAP](https://gsap.com)

## Usage
Usage is pretty straight forward:

```tsx
{/* Simply add the component to the root of your page */}

{/* And add your page's children */}

Lorem ipsum dolor sit, amet consectetur adipisicing elit.

```

To use GSAP tweens with ScrollTrigger a little extra code is needed:

```tsx
{/* Add these two lines to track page loaded state */}
const [loaded, __setLoaded] = useState(false);
useEffect(() => document.readyState === "complete" ? __setLoaded(true) : window.addEventListener("load", () => __setLoaded(true)), []);
```

```tsx
useEffect(() => {
{/* Place all gsap-related content in a gsap context like normal */}
const ctx = gsap.context(() => {
{/* Everything else is normal */}
gsap.to(polaroidsRef.current, {
x: `-${100 * polaroidsScale}%`,
scale: polaroidsScale,
scrollTrigger: {
scrub: true,
trigger: polaroidsRef.current,
end: "bottom"
}
});
});

return () => ctx.revert();
}, [
{/* Except down here... Make sure to add the loaded state to the dependency array */}
loaded
]);
```