Jquery 将项目悬停在“a”上标签
我有一个链接元素,当你将鼠标悬停在它上面时,会出现一个 div 。该 div 应该位于链接元素之上。当我移动鼠标时,显示的 div 会闪烁。有没有办法解决这个问题。我假设这是因为 div 现在覆盖了链接元素。
谢谢, C
I have a link element and when you hover over it a div appears. This div is meant to be over the link element. When I move my mouse the div that is showing flickers. Is there a way to fix this. I am assuming it is beacuse the div is now covering the link element.
Thanks,
C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你正在使用这样的代码:
在这种情况下,你的猜测是正确的。如果
div
悬浮在a
上,当div
显示时会触发鼠标离开,因为鼠标开始在a
上。 code>div 而不是在a
上。然后,div
被隐藏,鼠标再次输入a
...一切又重新开始。如果您可以避免
div
出现在上面(例如使用 z-index),那就更简单了。否则,我建议您执行以下操作:
如果您的鼠标在打开时始终位于
div
上,那么如果鼠标离开,它可以自行关闭。I guess you are using some code like this:
In this case, your guess is correct. If the
div
is floating over thea
, the mouse leave is triggered when thediv
is displayed, because the mouse starts to be on thediv
and not on thea
. Then, thediv
is hided, the mouse enter thea
again... And all begins another time.If you can avoid the
div
to appear over (with z-index, for example), it'll be more simple.Otherwise, I suggest you do something like this:
If your mouse will be always over the
div
when it's opened, then it can close itself if the mouse leaves.听起来您没有测试
div
是否已经可见。您可以使用以下代码测试可见性:希望这会有所帮助。
It sounds like you're not testing to see if the
div
is already visible or not. You test visibility using the following code:Hope this helps.
谢谢。这是我现在使用的代码...
$('area,#map-zoom').hover(function(){
$('#map-zoom').show();
},功能() {
$('#map-zoom').hide();
});
我也将悬停功能添加到出现的 div 中。
Thanks. Here is the code I am now using...
$('area,#map-zoom').hover(function(){
$('#map-zoom').show();
},function() {
$('#map-zoom').hide();
});
I have added the hover function to the appearing div aswell.