jQuery选择器,用于检查元素是否为隐藏动画 [英] jQuery selector to check if an element is animating to hidden
问题描述
有没有办法判断一个元素是隐藏还是当前正在隐藏(通过动画)?我能想到的唯一方法就是当你调用 show
或<时,在元素的数据
中存储一个标志。 code>隐藏,但我想知道是否还有其他办法?
Is there a way to tell if an element is either hidden or is currently in the process of hiding (via an animation)? The only way I can think to do it is to store a flag in the element's data
when you call show
or hide
, but I was wondering if there was another way?
推荐答案
可能你为它做一个自定义的jQuery选择器
Could you do a custom jQuery selector for it
(function($) {
var endOpacity,
oldStep = jQuery.fx.step.opacity;
$.fx.step.opacity = function( fx ) {
endOpacity = fx.end;
return oldStep(fx);
};
$.expr[':'].hiding = function(obj){
var $this = $(obj);
return ($this.is(':hidden') || ($this.is(':animated') && endOpacity === 0));
};
})(jQuery);
这对我有用(虽然可能需要更多测试)。
This worked for me (it may require some more testing though).
所以只需添加:隐藏
它将匹配隐藏的元素,以及当前被动画为0的元素。现在仅匹配正在消失但不显示的元素。
So just add :hiding
it will match hidden elements, and elements that are currently being animated to 0. It will now only match elements that are disappearing, not appearing.
这篇关于jQuery选择器,用于检查元素是否为隐藏动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!