Giter Club home page Giter Club logo

Comments (7)

jscottsmith avatar jscottsmith commented on June 2, 2024

targetElement could also be used to end an animation early, just depends how the target is positioned.

It would help to know the exact effect that you're trying to achieve, then I could show you how it might be done with this library, or advise to use something else instead.

from react-scroll-parallax.

hawret avatar hawret commented on June 2, 2024

Thank you for the quick answer :)

The green block should stop at the end of the purple
https://codesandbox.io/s/react-scroll-parallax-target-element-forked-wy97bc?file=/src/styles.css

from react-scroll-parallax.

jscottsmith avatar jscottsmith commented on June 2, 2024

Something like this?

https://codesandbox.io/s/react-scroll-parallax-target-element-stop-early-nev746?file=/src/App.tsx

from react-scroll-parallax.

hawret avatar hawret commented on June 2, 2024

It should start in the middle (my example) and end at the bottom of purple

from react-scroll-parallax.

hawret avatar hawret commented on June 2, 2024

This is a good example https://react-scroll-parallax-examples.vercel.app/
At the end, how would you stop the animation when the circles are aligned?
Or stopping the letters here https://react-scroll-parallax.netlify.app/

from react-scroll-parallax.

jscottsmith avatar jscottsmith commented on June 2, 2024

I'm just guessing here ;-)

Updated the CodeSandbox:
https://codesandbox.io/s/react-scroll-parallax-target-element-stop-early-nev746?file=/src/styles.css

They stop animating when the target is out of view and they are aligned because of their ending CSS position is aligned and no transform styles are used at the end of the effect translateY={[-200, 0]}.

Beyond that it's up to you to provide the correct styling to make it fit your specific needs.

from react-scroll-parallax.

hawret avatar hawret commented on June 2, 2024

That works, thanks! :))

A better API for this would be startScroll accepting self and add two others: duration and offset

// before translateY changes the original position
// I think `window.addEventListener('load', ...)` is required here
const start = window.pageYOffset + element.getBoundingClientRect().top
...
startScroll: (start - offset) 
endScroll: (start - offset) + duration

from react-scroll-parallax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.