[英]jQuery mouseover mouseout issue
I have some issue with a piece of code, i am using a sort of tooltip on links, but when a link has child elements in it, it blinks quick(when i hover over the child element(s)). 我对一段代码有问题,我在链接上使用了一种工具提示,但是当链接中包含子元素时,它会快速闪烁(当我将鼠标悬停在子元素上时)。
basic jQuery code(the part that shows the tip)(stripped down version, can not use a hover event!) 基本的jQuery代码(显示技巧的部分)(精简版,不能使用悬停事件!)
$('.aaa').bind('mouseover mouseout',function(e) {
if(e.type == 'mouseover'){
$('.tip').show()
}else{
$('.tip').hide()
}
});
this works 这有效
<a href="#" class="aaa"></a>
this works not(good) 这行不通(好)
<a href="#" class="aaa">
<img src="images/icon.png"/>
<span>text</span>
</a>
Use mouseenter and mouseleave instead of mouseover mouseout. 使用mouseenter和mouseleave代替mouseover mouseout。
Mouse over/out are triggered once for every child element. 每个子元素都会触发一次鼠标悬停。 Enter/leave are what you want/expect.
输入/离开您想要/期望的内容。 jQuery has normalized these across all browsers.
jQuery已在所有浏览器中对它们进行了标准化。
EDIT: here's a ref page: http://api.jquery.com/mouseenter/ 编辑:这是一个参考页: http : //api.jquery.com/mouseenter/
You should use the hover()
method 您应该使用
hover()
方法
var $tip = $('.tip');
$('.aaa').hover(
function() {
$tip.show();
},
function() {
$tip.hide();
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.