国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - Gilt die Animationsfunktion in jQuery als asynchrone Ausführung?
怪我咯
怪我咯 2017-06-26 10:51:31
0
2
1030
var mark2=true;
if(mark2){
               move(1);
               mark2=false;
} 
 function move(){
                    $(".box").animate({
                     width: arrW[index],
                      height: arrH[index],
                     opacity: arrO[index],
                     left: arrL[index],
                     top: arrT[index]

                    },500,function(){
                     mark2=true;
                    })


}

Der obige Code wird ausgeführtmove(1); mark2=false;這兩句的時候,move函數(shù)中用了animate動畫函數(shù),那move的調(diào)用是屬于異步的嗎?也就是放到任務隊列中執(zhí)行嗎,所以首先執(zhí)行mark2=false;Ist das richtig zu verstehen?

怪我咯
怪我咯

走同樣的路,發(fā)現(xiàn)不同的人生

Antworte allen(2)
漂亮男人

我看這個題主你可以直接在代碼上寫上console.log('')打印內(nèi)容來驗證你猜想的順序的。

jquery 的animate 是異步的,這個不用說吧,http://www.cnblogs.com/aaronj...

一般原理都是利用setTimeout之類的來定時延遲執(zhí)行,顯然animate的回調(diào)到點會放到任務隊列里,所以mark2=false肯定先執(zhí)行了

洪濤

調(diào)用move肯定是同步的阻塞的,
animate也是同步阻塞的

$(document).ready(function () {
    var mark2 = true;
    if (mark2) {
        move(1);
        console.log('運行結束')
    }
})

function move() {
    console.log("move start")

    $(".box").animate({
        width: 50,
        height: 50,
        opacity: 30,
        left: 200,
        top: 200
    }, {
        duration: 1500,
        start: function () {
            console.log("animate start")
        },
        complete: function () {
            console.log("animate end")
        }
    })

    console.log("move end")
}

結果是

first:25 move start
first:37 animate start
first:44 move end
first:20 運行結束
first:40 animate end

如果move不是同步的
你會先看到“運行結束”然后才是其他的東西
如果animate不是同步的
你會看到move end 在 animate start 前頭。
比如

$(document).ready(function () {
    var mark2 = true;
    if (mark2) {
        move(1);
        console.log('運行結束')
    }
})

function move() {
    console.log("move start")
    setTimeout(function () {
        $(".box").animate({
            width: 50,
            height: 50,
            opacity: 30,
            left: 200,
            top: 200
        }, {
            duration: 1500,
            start: function () {
                console.log("animate start")
            },
            complete: function () {
                console.log("animate end")
            }
        })
    }, 500)
    console.log("move end")
}

結果是

first:25 move start
first:45 move end
first:20 運行結束
first:36 animate start
first:39 animate end 
    
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage