jquery动画完成 [英] jquery animation done

查看:80
本文介绍了jquery动画完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个可滚动的选项卡类,工作正常,但现在我想隐藏控件,如果它们无法按照他们试图去的方向滚动。所以我有类似的东西;

Ok so I have a tab class that is scrollable which works fine, but now I want to hide the controls if they cannot scroll in the direction that they are trying to go. so I have something like this;

function tab_left(){
  $(".tab_link").each(function(){
    //animation here
  });
}

然后我想创建一个函数来确保它们都不是动画(因为如果他们在那里位置将不正确)。然后它会将图像固定到显示与否。我遇到的问题是检查它们中没有一个是动画的。任何帮助都表示赞赏。

Then I want to create a function that will make sure that none of them are animated(because if they are there position will not be correct). Then it will fix the image to either display or not. The problem I am having is checking that none of them are being animated. Any help is appreciated.

推荐答案

要检查元素是否正在设置动画,您可以这样做:

To check if an element is being animated you can do this:

if( $("#the-great-div").is(":animated") ){
  alert("Yay!");
}

或者如果需要,可以设置动画时调用的回调已完成: http://docs.jquery.com/Effects/animate

Or if you want, you can set a callback to be called when the animation is done: http://docs.jquery.com/Effects/animate

var finished = 0;
var callback = function (){
  // Do whatever you want.
  finished++;
}
$("#div").animate(params, duration, null, callback);

该回调参数通常可用于所有动画功能,而不仅仅是动画。最后,如果你想跟踪已经完成的项目数量,那么应该有一个全局变量(比如已完成)。

That callback parameter is usually available in all animation functions, not just animate. Finally, if you want to keep track of how many items have finished, a global variable should do (like finished in this case).

这篇关于jquery动画完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆