将'if'逻辑添加到jQuery链中

DA.*_*DA. 3 jquery jquery-chaining

假设我有以下jQuery:

// pseudocode  :
$(this)
    .doSomething
    .doSomething
    .selectSomething
        .doSomething
        .animate({ 
            opacity: 1
        }, 150)
        .end()
    .selectSomethingElse
        .doSomething
Run Code Online (Sandbox Code Playgroud)

我希望以上执行.但是,如果浏览器是IE,我不希望动画部分执行(由于IE无法使用透明PNG动画对象并保留PNG透明度).

反正有没有维护漂亮的链式jquery语法,但不知何故基于一些if逻辑跳过动画部分(在这种情况下测试IE)?

Tat*_*nen 6

你可以做一个each()并传递一个函数来处理它应该工作的动画.

$(this)
    .doSomething
    .doSomething
    .selectSomething
        .doSomething
        .each(function() {
            // Will return false on IE, true on others
            if(jQuery.support.opacity) {
                $(this).animate({ 
                    opacity: 1
                }, 150);
            }
        })        
    .end()
.selectSomethingElse
    .doSomething
Run Code Online (Sandbox Code Playgroud)