0
我需要的是:在一段时间后触发事件处理程序
如果用户将元素悬停1秒以上,事件就会发生,否则它不应该发生。
我试过使用setTimeout()
,但它只是延迟事件,并不会在鼠标离开元素时将其取消。
有没有其他方法可以解决这个问题?
$(".optionCont").live('mouseover', function(e){
var $this = $(this);
setTimeout(function(){
$(".dropMenuCont").stop(true,true).slideUp(200);
if($this.next().css("display") == "none"){
$this.next().stop(true,true).slideDown(200);
}else{
$this.next().stop(true,true).slideUp(200);
}
e.preventDefault();
e.stopPropagation();
return false;
}, 1000);
});
工作完美。谢谢! –
为什么不'mouseover'和'mouseout'?有什么区别?总之,本来要回答这个[测试用例](http://jsfiddle.net/aqDhj/)。 –
@Shadow:如果你输入元素的后代,'mouseout'和'mouseover'也会被触发。而且在大多数情况下,你不需要这样做。 –