beekai-oss / react-simple-animate

🎯 React UI animation made easy
https://react-simple-animate.now.sh/
MIT License
1.82k stars 61 forks source link

Prevent reverse animation, continue with the same animation. #87

Closed artidataio closed 3 years ago

artidataio commented 3 years ago

As seen in the Use Hooks to control Animate section of https://react-simple-animate.vercel.app/advanced, a boolean state will always reverse the animation when the state changes. Instead of reversing, I would like that the next button click will reuse the initial animation. Such that, Instead of going back to 0px, the square will go to the 400px. Can we do that with this package?

bluebill1049 commented 3 years ago

Try to reverser the start and end.

artidataio commented 3 years ago

Feels weird to me to reverse the end and start. But I got it.

  const handleClick = () => {
    setPlay(!play);
    if (play) {
      setStart(end + 200);
    } else {
      setEnd(start + 200);
    }
  };

full code here: https://codesandbox.io/s/use-hooks-to-control-animate-forked-1yhhw?file=/src/index.js