gpt4 book ai didi

jquery - 悬停时淡出/淡入背景图像

转载 作者:行者123 更新时间:2023-12-03 22:31:55 26 4
gpt4 key购买 nike

我有一个<div>其中包含背景图像,<div>位于 HTML 中的工具栏内。

HTML:

 <div id="toolbar">
<div class="image">&nbsp;</div>
</div>

CSS:

#toolbar .image {
background url('images/logo.png') no-repeat top left;
}

#toolbar .imagehover {
background url('images/logoHover.png') no-repeat top left;
}

当鼠标悬停在 #toolbar 上时我想要.image的背景图更改但使用 .fadeOut().fadeIn()

到目前为止我已经:

$("#toolbar").hover(function () {
$(".image").fadeOut("slow");
$(".image").addClass("imagehover");
$(".imagehover").fadeIn("slow");
},
function () {
$(this).removeClass("imagehover");
});

目前, Logo 淡出,悬停 Logo 淡入两次。

感谢任何帮助。

最佳答案

jQuery 中的图像之间无法实现平滑过渡 - 它不知道如何在一张图像和下一张图像之间进行转换。您可以使用插件进行颜色过渡。

您可以使用 CSS 过渡来完成一些操作。您只能对 CSS 中设置的值使用过渡,并且它们尚未在所有浏览器中使用:

/* faded out logo class */
.faded-logo {
opacity: 0.30; /* FX, Safari, GC, Opera, decent browsers */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; /* IE8 */
filter: alpha(opacity=30); /* IE */

background: url('images/logo.png') no-repeat top left;

/* in Safari, FX and Chrome add a fade transition */
-webkit-transition: opacity .25s linear .1s;
transition: opacity .25s linear .1s;
}

/* no opacity on hover */
.faded-logo:hover {
opacity: 1; /* FX, Safari, GC, Opera, decent browsers */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; /* IE8 */
filter: alpha(opacity=100); /* IE */
}

这将在鼠标悬停时产生漂亮的淡入淡出效果,不透明度的变化在 IE 中仍然会发生,但没有淡入淡出过渡。

另一种选择是使图像在彼此之上淡入和淡出 - 您可以使用 jQuery 悬停事件或 CSS 来做到这一点,但在任何一种情况下,您都需要将图像绝对定位在彼此之上。

关于jquery - 悬停时淡出/淡入背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2408761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com