最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

greensock TweenMax javascript - kill looping tween - Stack Overflow

programmeradmin0浏览0评论

I created a looping tween using Greensock javascript and 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.

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.

I created a looping tween using Greensock javascript and 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.

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.

Share Improve this question asked Dec 3, 2012 at 22:17 Papa De BeauPapa De Beau 3,82820 gold badges82 silver badges138 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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.

Two other tips:

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

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

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

TweenMax.killTweensOf($("#bigDVD"));
发布评论

评论列表(0)

  1. 暂无评论