javascript - Restart a velocity.js animation loop after stopping - Stack Overflow

I'm trying to find out if there's a way to restart a velocity animation after it has been sto

I'm trying to find out if there's a way to restart a velocity animation after it has been stopped.

Is there a velocity only way without applying a new animation with same properties again?

var box = $('.box');
box.velocity({rotateZ:'360deg'}, {duration:1000, loop:true});

// That's a dummy to explain what I'm trying  to do
setTimeout(function{
  box.velocity('stop');

  setTimeout(function(){
    box.velocity('START ORIGIN ANIMATION AGAIN');
  });
}, 2000);

I'm trying to find out if there's a way to restart a velocity animation after it has been stopped.

Is there a velocity only way without applying a new animation with same properties again?

var box = $('.box');
box.velocity({rotateZ:'360deg'}, {duration:1000, loop:true});

// That's a dummy to explain what I'm trying  to do
setTimeout(function{
  box.velocity('stop');

  setTimeout(function(){
    box.velocity('START ORIGIN ANIMATION AGAIN');
  });
}, 2000);
Share Improve this question edited Dec 22, 2014 at 3:18 G.Mart 5974 silver badges18 bronze badges asked Dec 20, 2014 at 15:43 BernieBernie 5,0655 gold badges43 silver badges73 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2

I know, it is a bit late response to the question. Velocity.js adds Pause / Resume (per element or global) feature to it since 1.4 version.

You can use the feature like this;

$element.velocity('pause');

or 

$element.velocity('resume');

I hope it helps.

Of course it's possible!

function Start() {

    var box = $('.box');

    DoRotation();

    $('#GoBtn').click(function() {

        box.velocity('stop').velocity({rotateZ:'0deg'}, {duration:1});

        setTimeout(DoRotation, 1000);

    });

    function DoRotation() {

         box.velocity({rotateZ:'360deg'}, {duration:1000, loop:true});
    }
}

$(Start);

And here's a jsFiddle to show it in action: http://jsfiddle/uy6578an/

I use something like this where I start and restart an amination and it works no problem, take a look at here to see it running on the timer: https://www.youtube./watch?v=bKEW02J3usA

It can be easily done with a setInterval() method.

var box = $('.box');
setInterval(function() {
    box.velocity({translateY: '-100%'}, 5000);
    box.velocity('reverse', {duration: 1});
}, 5000);

If what you mean is a pause()/resume() features, then no, it's currently not implemented in Velocity.

You'll have to manually restart your animation and you can use force-feeding to restart it from where you last stopped it.

As ydaniv mentioned, there is no pause / resume functionality.

However, you might have some success looking into Tweene as it extendeds Velocity.js and it's functionality.

To quote the Tweene docs "With Tweene you have now play(), pause(), resume(), reverse() and restart() methods for all supported libraries, for both tweens and timelines."

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401970a4626143.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信