greensock TweenMax javascript - 杀死循环补间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13692757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:29:49  来源:igfitidea点击:

greensock TweenMax javascript - kill looping tween

javascripttweengreensocktweenmax

提问by Papa De Beau

I created a looping tween using Greensock javascriptand I got it to loop using a function, maybe this is not the best way to loop, if you know a better way please advice, but basically when I try to kill the tween using this method, it doesn't work.

我使用Greensock javascript创建了一个循环补间,我让它使用一个函数循环,也许这不是最好的循环方式,如果你知道更好的方法请提供建议,但基本上当我尝试使用这种方法杀死补间时,它不起作用。

My code:

我的代码:

var dvdTween;
function playDVD()
{
 dvdTween = TweenMax.to($("#bigDVD"), 4, {css:{rotation:+1440, transformOrigin:"150px 150px"},ease:Expo.easeNone, delay:7, onComplete:playDVD});
}

/// Later in a function I call

/// 稍后在我调用的函数中

dvdTween.kill(); /// but this does nothing. 

Again, there may be a better way to loop a tween, and this may be my issue, but as of now this tween keeps on calling the function after I "kill" it.

同样,可能有更好的方法来循环补间,这可能是我的问题,但截至目前,这个补间在我“杀死”它后继续调用该函数。

Thanks for your tips and help.

感谢您的提示和帮助。

回答by Hyman

Your code should indeed work - I'd love to see an example set of files that shows it not working. I wonder if you're running into a scope issue or something - are you sure "dvdTween" is referencing the tween in the context you're calling it? Try adding onCompleteScope:this to your tween.

您的代码确实应该可以工作 - 我很想看到一组显示它无法工作的示例文件。我想知道您是否遇到了范围问题或其他问题 - 您确定“dvdTween”在您调用的上下文中引用了补间?尝试将 onCompleteScope:this 添加到您的补间。

Two other tips:

另外两个提示:

1) You can loop a TweenMax infinitely by setting repeat:-1, like:

1) 您可以通过设置 repeat:-1 无限循环 TweenMax,例如:

TweenMax.to($("#bigDVD"), 4, {css:{rotation:1440}, repeat:-1}); 

2) You can kill all the tweens of a particular object using TweenMax.killTweensOf() like:

2)您可以使用 TweenMax.killTweensOf() 杀死特定对象的所有补间,例如:

TweenMax.killTweensOf($("#bigDVD"));