2011-04-26 70 views
0
$("#div_id").click(function() { 
    $(this).effect("shake", { times:3 }, 300); 
    // Here I want wait that the div_id can complete its shake 
    alert('hello'); 
    } 

.delay我試過了,但它不工作。如何在Javascript中等待執行線?

+0

您需要使用*回調*。 – Orbling 2011-04-26 12:44:35

回答

2
$(this).effect("shake", { times:3 }, 300, function() { 

    // this will alert once the animation has completed 
    alert('hello'); 
}); 
0

如果你使用的是jQuery UI,你應該可以添加一個回調作爲第四個參數。

參見:http://jqueryui.com/demos/effect/

$("#div_id").click(function() { 
    $(this).effect("shake", { times:3 }, 300, function(){ 
     alert('hello'); 
    }); 
} 
0
$(this).effect("shake", { times:3 }, 300, function() { 
    alert('hello'); 
});