显示和隐藏 div 需要帮助

发布于 2024-10-09 08:15:55 字数 398 浏览 0 评论 0原文

我正在创建的图像查看器出现问题。如下图所示,“窗口”是显示图像的位置,“分页”是用户可以更改图像的位置。我使用这个 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');
});

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哎呦我呸! 2024-10-16 08:15:55

您可以在此处使用 .stop() 并将两者都包含在您的 .hover() 选择器,像这样:

$(".window, .paging").hover(function() {
    $(".paging").stop(true, true).fadeIn('fast');
}, function() {
    $(".paging").stop(true, true).fadeOut('fast');
});

这样,当你离开进入时子级或返回父级,它会停止淡出并将其带回,从而导致用户看不到任何可见操作。

You can use .stop() here and include both in your .hover() selector, like this:

$(".window, .paging").hover(function() {
    $(".paging").stop(true, true).fadeIn('fast');
}, function() {
    $(".paging").stop(true, true).fadeOut('fast');
});

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.

绝不服输 2024-10-16 08:15:55

您可以尝试使用 mouseovermouseout 代替。我不确定 mouseout 的反应是否与 hover 的反应相同。

You could try using mouseover and mouseout instead. I'm not sure that mouseout would react the same way hover does.

等往事风中吹 2024-10-16 08:15:55

事实上,当您将鼠标移到分页上时,会发生一件神奇的事情,称为“事件冒泡”:“悬停”事件被传递到“悬停”事件的父容器。悬停”对象,依此类推,直到“文档”对象。

因此,要解决您的问题,您需要停止冒泡,您可以使用“return false”来做到这一点:(

$(".paging").hover(function() {
    return false;
}, function() {
    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":

$(".paging").hover(function() {
    return false;
}, function() {
    return false;
});

(It's possible that in recent version of jquery you can replace the argument function(){return false;} by just false.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文