var start = $('#start_img');
start.on('click', function(){
var piano = $('.piano');
piano.each(function(index){
$(this).hide().delay(700 * index).fadeIn(700*index);
start.off('click');
})
});
你可以看到,我已經使用了start.off(「點擊」)方法,從一旦它被稱爲再次停止運行的事件監聽器。但事情是,我只想讓事件偵聽器在事件運行期間關閉。以便在事件仍在運行時不能再次調用它。但一旦事件結束,我希望它再次成爲'可調用'的。有誰知道如何做到這一點?暫時停止功能的jQuery
這樣做的其他方式(也不工作)。有人能幫我一下嗎。另一個現在很清楚。
var start = $('#start_img');
start.on('click', function() {
var q = 0;
var piano = $('.piano');
if (q === 1) {
return; // don't do animations
}
else{
piano.each(function(index) {
q = 1;
$(this).hide()
.delay(700 * index)
.fadeIn(700 * index, function() {
// remove from each instance when animation completes
q = 0
});
});}
});
直到淡出完成 – user7548524