鼠标悬停时在图像上显示信息

发布于 2024-08-31 21:14:30 字数 210 浏览 5 评论 0原文

我希望当鼠标滑过图像时能够在图像上显示信息(基本上是 HTML)...我知道有一个 .hover() jQuery 函数,但我不确定如何使用它以获得想要的效果。

理想情况下,当用户将鼠标悬停在图像上时,它会“变灰”(例如,50%不透明度的黑色层),并带有一些 HTML(如标题等)。

有人能给我指出正确的方向或提供示例代码吗?

谢谢

I want to be able to show information (HTML basically) over an image when the mouse rolls over the image... I know there is a .hover() jQuery function but am unsure how to use it to get the desired effect.

Ideally when a user hovers over an image it would "grey out" (e.g. layer of 50% opacity black) with some HTML like a title etc etc.

Can someone point me in the right direction or provide sample code

Thanks

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

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

发布评论

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

评论(2

情泪▽动烟 2024-09-07 21:14:30

您可以按照以下方式做一些事情:

包装您的图像和要显示的 div,如下所示:

<div class="imgHover">
    <div class="hover">Test Content for the hover</div>
    <img src="myImage.jpg" alt="" />
</div>

使用这样的 CSS:

.imgHover .hover { 
    display: none;
    position: absolute;
    z-index: 2;
}

最后,使用 .hover() 像这样:

$(".imgHover").hover(function() {
    $(this).children("img").fadeTo(200, 0.25)
           .end().children(".hover").show();
}, function() {
    $(this).children("img").fadeTo(200, 1)
           .end().children(".hover").hide();
});

您可以尝试上面的方法code out here

当您将鼠标悬停时,该图像会淡出并在其上方显示

,换行使得

是绝对位于 正上方,如果您需要大量包装内容,请为您的 .hover div 提供与图像相同的尺寸...仅取决于正是您想要的外观。

You could do something along these lines:

Wrap your image and the div to display, like this:

<div class="imgHover">
    <div class="hover">Test Content for the hover</div>
    <img src="myImage.jpg" alt="" />
</div>

With CSS like this:

.imgHover .hover { 
    display: none;
    position: absolute;
    z-index: 2;
}

And finally, the jQuery using .hover() like this:

$(".imgHover").hover(function() {
    $(this).children("img").fadeTo(200, 0.25)
           .end().children(".hover").show();
}, function() {
    $(this).children("img").fadeTo(200, 1)
           .end().children(".hover").hide();
});

You can try the above code out here

This fades the image out and displays the <div> above it when you hover, the wrapping is so that the <div> is absolutely positioned directly above the <img>, if you need a lot of wrapping content, give your .hover div the same dimensions as the image...just depends on the exact look you're going for.

偏闹i 2024-09-07 21:14:30

如果您无论如何都使用 jQuery,您可能需要一个工具提示插件:
http://www.webdesignbooth.com /15-jquery-plugins-to-create-an-user-friend-tooltip/

If you are using jQuery anyway, you might want a Tooltips plugin:
http://www.webdesignbooth.com/15-jquery-plugins-to-create-an-user-friendly-tooltip/

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