[ 5 posts ]

Josh Lizarraga

YUI Contributor

  • Offline
  • Profile

Pause an animation?

Post Posted: Thu Aug 06, 2009 4:24 pm
+0-
Hi all,

Is it possible to pause an animation and then restart it later?

Thanks!

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: Pause an animation?

Post Posted: Fri Aug 07, 2009 8:28 am
+0-
In 2.x you can't pause it, you have to stop it and then animate it again. However at that point it will start from the beginning. You can just rebuild the Anim config again and pass it to the instance before you animate it again..

Does that help?

Josh Lizarraga

YUI Contributor

  • Offline
  • Profile
Tags:

Re: Pause an animation?

Post Posted: Fri Aug 07, 2009 9:45 am
+0-
Yes! Thank you.

I used totalFrames - currentFrame to get the remaining frames, then used that to reanimate. :)

Joval b.

  • Username: ybh77
  • Joined: Sun Aug 16, 2009 9:20 am
  • Posts: 7
  • Offline
  • Profile
Tags:

Re: Pause an animation?

Post Posted: Mon Aug 17, 2009 10:59 pm
+0-
Hi,
How do you rebuild the config and pass it to the instance?

Josh Lizarraga

YUI Contributor

  • Offline
  • Profile

Re: Pause an animation?

Post Posted: Tue Aug 18, 2009 10:24 am
+0-
Keep track of the duration of the animation in a variable:

Code:
var oAnimTime = 10; // Seconds.


Then use the onComplete event to rebuild oAnimTime if the animation is paused:

Code:
var oAnim = new YAHOO.util.Anim(oTarget, {
      top: { to: 0 }
   }, oAnimTime, YAHOO.util.Easing.easeNone);
oAnim.onComplete.subscribe(function(){
   if(oSomeFlagThatDeterminesIfAnimWasPaused){
      oAnimTime = (oAnim.totalFrames - oAnim.currentFrame)/1000; // Divided by 1000 to get seconds.
   }
});


So when you rebuild the animation, oAnimTime is how many seconds were left instead of 10 seconds.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum