Jquery settimeout多次

时间:2014-04-10 15:19:55

标签: jquery settimeout

我的问题是......当我在链接上快速移动鼠标很多次时,框就是不要隐藏。它看起来像setTimeout被覆盖,旧函数停止工作 - 并且最终popup_remove()不会发生。请帮忙,我是jQ的初学者,已经用这个隐藏和展示框丢失了差不多两天。当我不使用settimeout并且只为mouseenter和mouseleave设置display:none时,一切都很有效。我想我只是不懂setTimeout方法。

我的JS:

timeout_on = {};
timeout_off = {};

$('.flex_section').delegate('a','mouseenter mouseleave',function(e){
   var a = $(this).attr('id')
   if (e.type == 'mouseenter'){

     timeout_on['id_'+ a] = setTimeout(function() { popup_show(a); }, 300);

   } else {

     timeout_off['id_'+ a] = setTimeout(function() { popup_remove(a); }, 300)

   }
});

popup_show(type){
     $('#someID_' + type).css('display','block')
     clearTimeout(timeout_on['id_'+ type])
}
popup_remove(type){
     $('#someID_' + type).css('display','none')
     clearTimeout(timeout_off['id_'+ type])
}

1 个答案:

答案 0 :(得分:0)

也许你必须在设置另一个之前清除Timeout?

鼠标输入:   - 添加超时输入 鼠标离开:   - 删除旧的超时   - 为离开添加超时 ...

相关问题