jQuery:在某些情况下不要鼠标移开
我有一个非常基本的问题,我无法解决(可能是因为现在是凌晨 5 点)。它可以简化为以下内容:
HTML:
<img src="image.jpg" alt="logo" />
<span class="caption">This is a caption</span>
JS:
$("img").mouseover(function() {
$('.caption').show();
});
$("img").mouseout(function() {
$('.caption').hide();
});
使用 CSS,我使用 z-index 属性和绝对定位将标题放置在图像顶部。问题在于,标题悬停后就会消失,如果鼠标仍在移动,标题就会再次出现,从而导致闪烁的烦恼。
显然这不应该发生。基本上,当标题本身悬停时,不应调用 mouseover 事件。有人解决了吗?
I've got a pretty basic question that I can't wrap my head around (possibly since it's 5 AM here). It can be simplified to the following:
HTML:
<img src="image.jpg" alt="logo" />
<span class="caption">This is a caption</span>
JS:
$("img").mouseover(function() {
$('.caption').show();
});
$("img").mouseout(function() {
$('.caption').hide();
});
Using CSS, I positioned the caption on top of the image using the z-index property and absolute positioning. The problem is that the caption will disappear once it's hovered, then reappear again if the mouse is still moving, resulting in a blinking annoyance.
Obviously this is not meant to happen. Basically, the mouseover event shouldn't be called when the caption itself is hovered. Anyone got a fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
HTML:
JS:
How about this:
HTML:
JS: