[英]Hover acting weird in IE
Have a look at this HTML code: 看一下下面的HTML代码:
<div class="overlay">
<a href="#">1</a>
<a href="#">1</a>
<a href="#">1</a>
<a href="#">1</a>
<a href="#">1</a>
</div>
and this jQuery code: 和这个jQuery代码:
$('div.overlay').mouseenter(function() { clearTimeout(thumbsAway); });
$('div.overlay').mouseleave(function() { clearTimeout(thumbsAway); $('ul.thumbs').animate({top: '520px'}, 750); });
The problem is that in IE, hovering on any child element will also trigger mouseenter/mouseleave. 问题在于,在IE中,将鼠标悬停在任何子元素上也会触发mouseenter / mouseleave。 How can I prevent this?
我该如何预防?
You can use event.stopPropagation() 您可以使用event.stopPropagation()
$('div.overlay').hover(function(event){
event.stopPropagation();
clearTimeout(thumbsAway);
},
function(event){
event.stopPropagation();
clearTimeout(thumbsAway);
}
);
Or check the target of the event. 或检查事件的目标。
$('div.overlay').hover(function(event){
if (this == event.target){clearTimeout(thumbsAway);}
},
function(event){
if (this == event.target){clearTimeout(thumbsAway);}
}
);
Try stopping the event propogation with stopPropogation()
: 尝试使用
stopPropogation()
停止事件传播:
$('div.overlay').mouseenter(function(e) {
e.stopPropogation();
clearTimeout(thumbsAway);
});
Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
说明:防止事件使DOM树冒泡,从而防止任何父处理程序收到该事件的通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.