我有這個估計。我有一個setTimeout函數,其中我淡出和淡入元素。在幾秒鐘內,這個超時被清除,並且在被調用.hide()後立即隱藏這個元素。問題是有時它不隱藏元素。我有一種感覺,它與時間有關。cleartimeout函數完成後執行(jQuery)
例子:
function first_func(){
$('.element').fadeOut(function(){
// Do other stuff like change element's position
$('.element').fadeIn();
});
interval1 = setTimeout(function(){first_func()},500);
}
function second_func(){
countdown--;
if (countdown<0){
last_func();
}
interval2 = setTimeout(function(){second_func()},1000);
}
function begin_func(){
first_func();
second_func();
}
function last_func(){
clearTimeout(interval1);
clearTimeout(interval2);
$('.element').hide();
}
所以基本上問題是,在last_func我同時清除間隔和隱藏元素,但有時該元素的網頁上仍然可見。所以我猜測,它並隱藏,但間隔仍在進行中,並在消失回去。
如果有人有一些建議,請
對不起,我一直在從頭開始寫它,我現在沒有我的實際來源。當然在調用end_func()之後;我確實回來了;以及。基本上一切工作都很好,只是有時元素不會隱藏 – Tom 2012-03-29 09:14:49
@Tom ok,但考慮在調用hide之前添加'stop(true,true)',這可能有所幫助。 – Niko 2012-03-29 09:17:13
好吧,我想最好向您展示真實的代碼,您可以在www.tomasdostal.com/projects/thirst_game上看到它。但代碼很雜亂 – Tom 2012-03-29 09:18:03