我有这个估计。我有一个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