Is there a way to prevent the execution of onComplete if the animation was
- overridden / interrupted or
- never occured in the first place (because it was realized via
to()and the value was already met)?
I assume onInterrupt could be used for that? If so, how?
Here is a jsfiddle example: https://jsfiddle.net/2f1jbwra/2/
jsfiddle with kill(): https://jsfiddle.net/2f1jbwra/4/
jsfiddle with overwrite: "auto": https://jsfiddle.net/2f1jbwra/5/
CodePudding user response:
You can use the onInterrupt callback by using that property on the tween or by using .addEventListener().
onInterrupt: () => {
// Remove the onComplete
this.addEventListener("onComplete", null);
}
Demo.
With that being said, it won't fire if the tween never fired in the first place. But tweens where the start and end values are the same (like the situation that you describe in the question) are still ran like normal. It's just that you can't see any changes because none happen visually.
FYI you're more likely to get even quicker answers and additional commentary/helpful info and approaches if you ask GSAP specific questions like this in the GSAP forums.
