Jump to content
Search Community

timeline from the onUpdate function comes undefined since the 3.0.2

ugo test
Moderator Tag

Recommended Posts

Hey,

 

I recently build a progressbar component using GSAP. I was able to manage with the live display of the progress using the onUpdate function from the fromTo. It was working fine under the 3.0.1 version until it comes undefined with the 3.0.2.

Is there anything I can do to fix that ?

 

 gsap.fromTo(activeBarElement, .5,
            { 
                strokeDashoffset: getProgress(fromProgress)
            },
            {
                onUpdate: (timeline) => { 
                  // since the 3.0.2 version GSAP, timeline is always undefined
                  		if(timeline) { 
  							 console.log(timeline.progress())                      
                        }
                    }
                },
                strokeDashoffset: getProgress(toProgress),
                stroke: getCssColor(toProgress),
                ease: Linear.easeInOut
            });

 

Link to comment
Share on other sites

Yeah, sorry about any confusion there - initially in GSAP 3, I thought it'd be convenient to default to returning the animation instance itself as the only parameter if none were defined (like onUpdateParams), but several people (Blake included) advised against that for various reasons one of which is that it's easy enough to get using the "this" keyword. So it was removed in 3.0.2 and beyond, making it behave like it always did in all previous versions before 3.0.0. Just beware that arrow functions lock scope, so you need to use a regular function. So I assume this is more like what you wanted:

 

gsap.fromTo(activeBarElement, {
		strokeDashoffset: getProgress(fromProgress)
	}, {
		duration:0.5, 
		onUpdate: function() {
			console.log(this.progress());
		}
	},
	strokeDashoffset: getProgress(toProgress),
	stroke: getCssColor(toProgress),
	ease: "none"
});

 

Better? 

  • Like 1
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...