Jquery 关于悬停时背景图像更改的建议/帮助
有人能给我推荐一个插件,它可以改变背景图像/悬停在不同按钮上的图像吗Jquery 关于悬停时背景图像更改的建议/帮助,jquery,css,html,twitter-bootstrap-3,Jquery,Css,Html,Twitter Bootstrap 3,有人能给我推荐一个插件,它可以改变背景图像/悬停在不同按钮上的图像吗 有三个按钮,每个按钮对应一个图像。因此,当我将鼠标悬停在按钮上方时,这些按钮后面的图像应该会改变。我被卡住了 当你用谷歌搜索时,你可以浏览100个例子。。无论如何,我建议你四处看看,以下问题可能会对你有所帮助。。 ,这是最简单的方法:,它使用此精灵表: 有两种方法可以做到这一点。轻量级的方法是使用CSS,如下所示: #mylink-1 { background: transparent url('/img/my-img.p
有三个按钮,每个按钮对应一个图像。因此,当我将鼠标悬停在按钮上方时,这些按钮后面的图像应该会改变。我被卡住了 当你用谷歌搜索时,你可以浏览100个例子。。无论如何,我建议你四处看看,以下问题可能会对你有所帮助。。 ,这是最简单的方法:,它使用此精灵表: 有两种方法可以做到这一点。轻量级的方法是使用CSS,如下所示:
#mylink-1 {
background: transparent url('/img/my-img.png') 0 0 no-repeat;
}
#mylink-1:hover {
background: transparent url('/img/my-img-over.png') 0 0 no-repeat;
}
#mylink-2 {
background: transparent url('/img/my-img-2.png') 0 0 no-repeat;
}
#mylink-2:hover {
background: transparent url('/img/my-img-2-over.png') 0 0 no-repeat;
}
或者,使用精灵图纸:
#mylink-1 {
background: transparent url('/img/my-img.png') 0 0 no-repeat;
}
#mylink-1:hover {
background: transparent url('/img/my-img-over.png') 0 -20px no-repeat;
}
第二种方法是JavaScript。如果您正在使用jQuery:
$('#mylink-1').on('hover', function() {
$(this).css({ background: 'transparent url("/img/my-img-over.png") 0 0 no-repeat' });
});
如果您有很多图像,并且使用数字命名图像或使用精灵,您可以执行以下操作:
var i = 1;
// Non-sprite
#('.mylinks').each(function() {
$(this).css({ background: "transparent url('/img/my-img-' + i +'-over.png') 0 0 no-repeat" });
i++;
});
var i = 0;
// Using sprites
#('.mylinks').each(function() {
$(this).css({ background: "transparent url('/img/my-img-over.png') 0 ' + i + 'px no-repeat" });
i -= 20;
});
为什么不在css中执行此操作
#button1:hover
{
background: url(/image/btn1.png) no-repeat;
}
#button2:hover
{
background: url(/image/btn2.png) no-repeat;
}
#button3:hover
{
background: url(/image/btn3.png) no-repeat;
}
到目前为止你尝试了什么?你能把你的代码贴在这里吗?我不需要改变按钮的图像。。当你把鼠标悬停在上面时,我需要更改jumbotron的背景图像buttons@prawwe316我把小提琴加在柱子的顶端。希望这有帮助!谢谢你,克里斯。。我感谢你的帮助。我想我没有正确地解释这个问题。。。我在jumbotron中使用了这三个按钮。当我把鼠标悬停在它们上面时,巨无霸中的图像应该会改变