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?
views:
93answers:
2
+1
A:
You get the hidden one with $(":hidden") and then the animating ones with $(":animated") and with the :animated check the .queue() if it has the hide method inside.
Jakub Hampl
2010-05-12 00:54:32
I checked the queue with this code: `$el.slideUp('slow'); console.log($el.queue())` and all it had in it was `["in progress"]`
nickf
2010-05-12 01:36:04
Well that's all the pointers I can give you - probably if you checked the jQuery source you might find a way to read of entries out of the queue object.
Jakub Hampl
2010-05-12 01:47:20
+3
A:
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).
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.
alex
2010-06-03 00:44:17
this is a good start, but I think you'll hit issues when there's more than one element. See this: http://jsbin.com/ojuro3/2/edit -- click the paragraphs to make them fade out and in. Every second, hiding ones are coloured red, and non-hiding ones blue.
nickf
2010-06-04 09:14:20
@nickf What about this, if you remove the element checking http://jsbin.com/ojuro3/3/edit
alex
2010-06-04 10:54:59