Javascript jQuery 暂停/恢复动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5586068/
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-08-23 17:56:16  来源:igfitidea点击:

jQuery Pause / Resume animate

javascriptjqueryjquery-animate

提问by Suraj

This ain't working for me...

这对我不起作用...

$(document).ready(function(){
    $('#h .a').animate({
        top:'-=80px'
    },90,'linear');

    $('#h .au,#h .di').animate({
        left:'-=80px'
    },50000000,'linear');

    $('#h .r').animate({
        left:'-=80px'
    },250,'linear');

    $("#h").animate('pause'); //pausing it at the start
    //resume pause switch
    $("#h").mouseover(function(){
      $(this).animate('resume');
    }).mouseout(function(){
      $(this).animate('pause');
    });

});

采纳答案by Adam Terlson

Check out the demo here: http://api.jquery.com/clearQueue/

在这里查看演示:http: //api.jquery.com/clearQueue/

Looks like exactly the sort of thing you're trying to do.

看起来正是你想要做的那种事情。

回答by ShirazITCo

try this one for pause and resume: jQuery Pause / Resume animation plugin

试试这个暂停和恢复:jQuery Pause / Resume animation plugin

also we $(this).stop()can pause animate but no chance to resume!

我们$(this).stop()也可以暂停动画但没有机会恢复!

other mistake is this one: top:'-=80px'

另一个错误是这个: top:'-=80px'

first try to get current position like this then add position to it:

首先尝试像这样获取当前位置,然后为其添加位置:

_top = $(this).offset().top;

$('#h .a').animate({
    top:_top-80
},90,'linear')

回答by Samg

Check the plugin: Fxqueues

检查插件:Fxqueues

https://github.com/lucianopanaro/jQuery-FxQueues

https://github.com/lucianopanaro/jQuery-FxQueues

It supports both pause and resume (without clearing the queue) and adds the idea of Scopes. Scopes are great for chaining animations across multiple objects.

它支持暂停和恢复(不清除队列),并添加了 Scopes 的思想。范围非常适合跨多个对象链接动画。

I haven't found a version of Fxqueus for the current version of Jquery, but have used it successfully with older Jquery versions.

我还没有找到适用于当前 Jquery 版本的 Fxqueus 版本,但是已经成功地将它用于较旧的 Jquery 版本。

回答by Hussein

Use queue()and dequeue()functions. Here's an example taken directly from jQuery documentation.

使用queue()dequeue()函数。这是直接取自 jQuery 文档的示例。

Check working example at http://jsfiddle.net/j4SNS/

http://jsfiddle.net/j4SNS/检查工作示例

回答by S Pangborn

You'll want to look into using the .stop()function for this, as it'll stop any animations on a jQuery element.

您需要考虑为此使用该.stop()函数,因为它会停止 jQuery 元素上的任何动画。

http://api.jquery.com/stop/

http://api.jquery.com/stop/