【发布时间】:2012-03-29 17:24:26
【问题描述】:
我有这种情况。我有一个 setTimeout 到一个函数,我在其中淡出和淡入一个元素。在几秒钟内,这个超时被 cleartimeout 清除,然后调用 .hide() 来隐藏这个元素。问题是有时它不会隐藏元素。我感觉这和时间有关系。
例子:
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 中我清除了间隔并隐藏了元素,但有时该元素在页面上仍然可见。所以我猜它确实隐藏了,但间隔仍在进行中,它会淡入。
如果有人有什么建议,请
【问题讨论】:
标签: javascript jquery intervals