显示和隐藏 div 需要帮助
我正在创建的图像查看器出现问题。如下图所示,“窗口”是显示图像的位置,“分页”是用户可以更改图像的位置。我使用这个 Jquery 脚本使“分页”在窗口悬停时淡入 - 它一开始是隐藏的。尽管当用户将鼠标悬停在“寻呼”上时,它会闪烁。 (比如显示然后隐藏等)
我想这是因为鼠标不再悬停在“窗口”上。谁能建议我如何让“寻呼”保持显示?感谢您的帮助! :)
$(".window").hover(function() {
$(".paging").fadeIn('fast');
}, function() {
$(".paging").fadeOut('fast');
});
I'm having a problem with an image viewer I'm creating. Like the image below, the 'window' is where the image is shown and 'paging' is where the user can change the image. I've used this Jquery script to make the 'paging' fade in whenever the window is hovered over - It's hidden to start with. Although when the user hovers onto 'paging', it flickers. (Like shows then hides, etc.)
I suppose it's because the mouse isn't hovering over the 'window' anymore. Can anyone suggest how I can make 'paging' remain showing? Thanks for the help! :)
$(".window").hover(function() {
$(".paging").fadeIn('fast');
}, function() {
$(".paging").fadeOut('fast');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在此处使用
.stop()
并将两者都包含在您的.hover()
选择器,像这样:这样,当你离开进入时子级或返回父级,它会停止淡出并将其带回,从而导致用户看不到任何可见操作。
You can use
.stop()
here and include both in your.hover()
selector, like this:This way, when you leave to enter the child or back to the parent it stops the fade out and brings it right back, resulting in no visible action to the user.
您可以尝试使用
mouseover
和mouseout
代替。我不确定mouseout
的反应是否与hover
的反应相同。You could try using
mouseover
andmouseout
instead. I'm not sure thatmouseout
would react the same wayhover
does.事实上,当您将鼠标移到分页上时,会发生一件神奇的事情,称为“事件冒泡”:“悬停”事件被传递到“悬停”事件的父容器。悬停”对象,依此类推,直到“文档”对象。
因此,要解决您的问题,您需要停止冒泡,您可以使用“return false”来做到这一点:(
在最新版本的 jquery 中,您可能可以将参数 function(){return false;} 替换为 false 。)
In fact, when you pass your mouse over the paging there is a magical thing that happens which is called "event bubbling": the "hover" event is passed to the container which is the parent of the "hovered" object, and so on until the "document" object.
So to solve your problem, you need to stop bubling, you can do it with "return false":
(It's possible that in recent version of jquery you can replace the argument function(){return false;} by just false.)