Jump to content
Search Community

onUpdate callback function problem

ashura test
Moderator Tag

Recommended Posts

Hi no need for big explanation here how can I get the progress of animation in a gsap? is it a onUpdate or what? 
cause I'm trying to update the animation in a canvas 

Here is the code, but it seems like it is giving me undefined and null...its completely nothing..care anyone to explain if I'm using it wrong? 

 

        tl.add(
            gsap.to(
            {},
            {
                duration: 0.5,
                onUpdate: (animation) => {
                    console.log(animation)
                // drawCircles(i, animation.progress());
                },
            }
            )
        );

 

Link to comment
Share on other sites

Thanks pal @PointC however I find more alternative cause I'm using a typescript 

which might be better..

 

            const progressProxy = { progress: 0 };
            tl.add(
                gsap.to(progressProxy, {
                duration: 1,
                onUpdate: () => {
                    drawCircles(i, progressProxy.progress);
                },
                })
            );

 

Link to comment
Share on other sites

Just beware that the one from @PointC will have no easing applied which I assume is what you want, but your example is actually tweening a value on an object, thus the default easing would be applied. You should set ease: "none" on yours if you want to eliminate the easing. 

 

Another option is to leverage getter/setter methods: 

let proxy = {
  _p: 0,
  getProgress: () => proxy._p,
  setProgress(progress) {
    console.log("progress", progress);
    proxy._p = progress;
    //drawCircles(i, progress);
  }
};
gsap.to(proxy, {
  setProgress: 1,
  ease: "none",
  duration: 2
});

 

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...