Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用单击图像映射更改设置为背景的精灵图像的位置_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 使用单击图像映射更改设置为背景的精灵图像的位置

Javascript 使用单击图像映射更改设置为背景的精灵图像的位置,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我已经找了大约一个小时来解决我的问题,但找不到什么帮助 我有一个将精灵图像设置为背景图像的div,这样在一个jpg中一个图像位于另一个图像之上。当您将鼠标悬停在div上时,它会更改精灵图像的位置,以便您看到另一种状态 我想使用图像映射,这样当您单击背景图像的一部分时,这将更改精灵背景图像的位置以显示替代状态。再次单击它将使其返回原始状态 我希望这是有意义的,谢谢你抽出时间 .imageswap { list-style: none; height: 495px; widt

我已经找了大约一个小时来解决我的问题,但找不到什么帮助

我有一个将精灵图像设置为背景图像的div,这样在一个jpg中一个图像位于另一个图像之上。当您将鼠标悬停在div上时,它会更改精灵图像的位置,以便您看到另一种状态

我想使用图像映射,这样当您单击背景图像的一部分时,这将更改精灵背景图像的位置以显示替代状态。再次单击它将使其返回原始状态

我希望这是有意义的,谢谢你抽出时间

.imageswap {
    list-style: none;
    height: 495px;
    width: 940px;
    display: block;    
    background: url('/HTMLContent/images/frozenpeas_web_sprite3.jpg') 0 0;
}

.imageswap:hover{
    background-position: 0 -495px;
}

做冰球
冰块和清凉饮料就像豆荚里的豌豆,这就是我们为您带来冷冻豌豆冰块的原因!冷冻冰豌豆从你自己的冰箱里自产,完全可重复使用。非常适合吃豌豆的场合,或者只是在电视机前闲逛。简单的豌豆
Alessandro Martorelli设计


这就是你要找的吗

CSS:

jQuery:

$(".imageswap").click(function() {
    $(this).toggleClass("active");
});

我想这就是你需要的:

要帮助在图像顶部放置链接,请参考以下内容:

希望这有帮助

.imageswap.active,
.imageswap:hover {
    background-position: 0 -495px;
}
$(".imageswap").click(function() {
    $(this).toggleClass("active");
});