gpt4 book ai didi

html - 我需要一些关于动态设置悬停 BG 的说明

转载 作者:行者123 更新时间:2023-11-28 13:13:28 25 4
gpt4 key购买 nike

这是我的代码:

function recordStarted() {
$("#red_button").css("background","url(stop.png)");
$("#red_button").css("background-repeat","no-repeat");

$("#red_button:hover").css("background","url(stop-hover.png)");
$("#red_button:hover").css("background-repeat","no-repeat");
}

我已经通过第二行设置了 div 层的背景,但是当我尝试设置悬停背景时,它就变成了背景。我将如何动态设置 :hover 背景?

CSS:

.red_button 
{
background:url(record.png);
padding: 19px 251px;
cursor: pointer;
background-repeat: no-repeat;
}

.red_button:hover
{
background:url(record-hover.png);
cursor: pointer;
background-repeat: no-repeat;
}

最佳答案

这就是 jQuery。 :hover 不是 jQuery 选择器的一部分。你可以在 css 中做到这一点。但是如果你出于某种原因决定在其中做 jQuery,你应该做的是将 stop.png 的背景图像分配给你的 css 到#red_button。然后也添加到您的 css #red_button.hover 并将其他图像分配给它作为背景。然后在 jQuery 中使用

$("#red_button").hover(function () {
$(this).addClass("hover");
},
function () {
$(this).removeClass("hover");
});
});

关于html - 我需要一些关于动态设置悬停 BG 的说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15237917/

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