JS鼠标移入/移出闪烁但不停留

3

这里有一段我遇到问题的代码:

$(".setEtiquette").mouseover(function(){
    var rightFrame = $(this).attr("name");
    $('#'+rightFrame).fadeIn();
}).mouseout(function(){
    var rightFrame = $(this).attr("name");
    $('#'+rightFrame).fadeOut();
});

当设置Etiquette时,右侧框架会闪烁,但这不是我们想要的效果,我们希望它保持不变,并在移动到另一个Etiquette时离开...

你有什么可以帮助我的吗?

谢谢!


1
问题在于当鼠标移出时,rightFrame 应该离开。删除 mouseout 不起作用,因为它会使 rightFrame 保持可见。使用 mouseenter、mouseleave 就可以解决问题,而不会反复触发 rightFrame ^^ - kfa
1个回答

4

当指针移动到子元素时,mouseover() 会触发,而mouseenter() 只会在指针移动到绑定元素时触发。 如果闪烁是由于您绑定的元素已有子元素,则可以尝试使用 mouseenter/mouseleave 替代 mouseover/mouseout。


值得一提(对于非jQuery用户),onmouseenter / onmouseleave是非标准的Microsoft事件。然而,jQuery模拟这个事件以支持跨浏览器。 - MrWhite

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接