Jump to content
Search Community

Easing weird behavor on the end of a tween

RonceBleue test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hello,

 

I encounter an issue with easings. Basically the problem is that animation speed up at the end of a tween, even when I stipulate ease:none in a tween.

 

I can't reproduce on a codepen, I am working on a nextJs project. Here is the component that is animated

export default function Template({ children }: { children: React.ReactNode }) {
  const transition = useRef(null);

  useGSAP(() => {
    transitionEnter();
  }, []);

  return (
    <div className='relative h-screen w-full overflow-hidden'>
      <div
        ref={transition}
        id='transition-wrapper'
        className='absolute left-0 top-0 h-full w-full bg-black transition'
      ></div>
      {children}
    </div>
  );
}

 

And here is my animations

export const transitionEnter = () => {
  const el = document.querySelector('#transition-wrapper');
  const tl = gsap.timeline({
    onStart: () => {
      console.log('transition start');
    },
    onComplete: () => {
      console.log('transition end');
    },
  });

  tl.to(el, {
    y: window.innerHeight,
    ease: 'none',
    duration: 1,
  });
};

export const transitionLeave = (router: AppRouterInstance, route: string) => {
  const el = document.querySelector('#transition-wrapper');

  const tl = gsap.timeline({
    onStart: () => {
      console.log('enter start');
    },
    onComplete: () => {
      console.log('enter end');
      router.push(route);
    },
  });

  tl.to(el, {
    y: 0,
    duration: 1,
    ease: 'none',
  });
};

 

And the result here, we can clearly see that the animation speed is not linear. And it is even worst when I use other easing function.

 

I think there may be something to do with useGsap/Next but I run out of idea. If someone have some ideas. 

 

Thanks.

 

Link to comment
Share on other sites

Hi @RonceBleue and welcome to the GSAP Forums!

I see you're using React -

Proper cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE.

 

Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down.

 

Here is how it works:

const container = useRef(); // the root level element of your component (for scoping selector text which is optional)

useGSAP(() => {
  // gsap code here...
}, { dependencies: [endX], scope: container }); // config object offers maximum flexibility

Or if you prefer, you can use the same method signature as useEffect():

useGSAP(() => {
  // gsap code here...
}, [endX]); // simple dependency Array setup like useEffect()

This pattern follows React's best practices.

 

We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/

 

If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. 

 

We also have this starter templates collection in Stackblitz for React and Next:

https://stackblitz.com/@GreenSockLearning/collections/gsap-react-starters

 

https://stackblitz.com/@GreenSockLearning/collections/gsap-nextjs-starters

 

Feel free to fork one of those in order to recreate the issue you're having, just remember to keep your demo as small as possible, no need to add your full project in it.

 

Happy Tweening!

Link to comment
Share on other sites

  • Solution


As the GSAP Helper already mentioned, without a minimal demo it is close to impossible to tell for sure, but my best guess would be that you are using some CSS fraework like probably tailwind, judging from the classes on the element you are animating with GSAP.

If that is the case, here's what tailwind'stransitionclass will add via CSS

https://tailwindcss.com/docs/transition-property
 

transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;


So my guess is that you have CSS transitions fighting with updates on the element done by GSAP.


On properties of elements that you are going to tween on with GSAP, you should never have transitions applied.

This older demo of mine illustrates why.


See the Pen JjmrMNy by akapowl (@akapowl) on CodePen


 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...