javascript - jQuery:使用 .stop(xxx, false) 调用 'complete' 回调

标签 javascript jquery callback jquery-animate

有一个库 X 可以对元素 '.the-element' 进行动画处理,并在动画结束时附加一个简单的 complete 回调。必须调用该回调,否则库 X 将停止工作。

库 X 本身不支持卡住(也称为暂停所有动画它们所在的位置),因此我尝试执行 jQuery('.the-element').stop(false,假);。但现在回调没有被调用。由于 jQuery 不支持恢复暂停的动画(这是首选,但我不想为此使用插件),我想自己调用 complete 回调,以便库 X 可以继续它所做的事情。

所以问题来了:如何在使用 .stop(xxx, false) 时调用 complete 回调?

最佳答案

您可以使用 $.fn.animate()options 对象将回调放置在另一个事件中(在您的情况下,它总是 );

$(".the-element").animate(
    {property: 'value'}, {
        duration: 1000,
        done: function() {/* ... */}, // executes when animation reached end value
        complete: function() {/* ... */}, // executes when animation is complete
        fail:  function() {/* ... */}, // executes when animation don't go to end
        always: function() {/* ... */}, // executes always when animation is ended,
                                        // it may be completed or interrupted/stopped
    }
);

Reference for $.fn.animate() .

关于javascript - jQuery:使用 .stop(xxx, false) 调用 'complete' 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26716028/

相关文章:

javascript - 我可以在 javascript 中扩展控制台对象(用于重新路由日志记录)吗?

javascript - (React) 动态组件条件设置状态

Zend 和 jQuery Mobile 中的 JavaScript

jquery - 当鼠标单击并拖动然后退出时,如何在鼠标移出时淡出?

jquery - 如何通过 jQuery 中的 SetTimeout 函数传递元素 ID?

c# - 如何在 C# 中的静态类中创建一个简单的回调

多个 ajax 调用的 jQuery 回调

javascript - 从 Google Maps API V3 获取旅行距离和旅行时间

javascript - 多个 $.each 中的 setTimeout() 回调

javascript - Emberjs IE8 对象预期错误