开发者

Manually add ":animated" selector to jQuery objects

开发者 https://www.devze.com 2023-02-19 21:08 出处:网络
I have a function that animates dom elements with CSS3 if available. Now i often use the :animeted jQuery selector. How do i make my CSS3 Animated elements respond to :animeted selector also?

I have a function that animates dom elements with CSS3 if available. Now i often use the :animeted jQuery selector. How do i make my CSS3 Animated elements respond to :animeted selector also?

When a DOM Object is animated with jQuery it gets "fxqueue":"inprogress" in the Data object, so i was thinking i could manually add my elements using:

$("div").eq(0).data({"fxque开发者_开发百科ue": "inprogress"});

but

console.log( $("div:animated") )

does not select anything.


That won't work.
The :animated filter is defined as

jQuery.expr.filters.animated = function( elem ) {
    return jQuery.grep(jQuery.timers, function( fn ) {
        return elem === fn.elem;
    }).length;
};

It checks whether the element is in jQuery.timers.

Instead, you can replace the :animated selector:

var originalAnimated = jQuery.expr.filters.animated;
jQuery.expr.filters.animated = function(elem) { 
    return originalAnimated(elem) || something;
};
0

精彩评论

暂无评论...
验证码 换一张
取 消