1
我有一个需要在背景图像和大小之间切换的div。我能够获得最初(第一次)点击以正确更改背景图像和div大小,但是当我再次单击它时,我无法将其恢复为原始大小和背景图像。任何人都可以向我解释我需要做什么?在jQuery中切换图像和更改div大小
CSS
#navigation{
position: absolute;
display: block;
float: right;
margin: 0;
top: 0;
right: 0;
width: 25px;
height: 100%;
background-image: url(../images/left.png);
background-repeat: no-repeat;
background-position: left;
z-index: 3;
background-color: green;
}
JS
$("#navigation").on("click", function(){
if($(this).css("background-image", "url(images/left.png)")){
$(this).css("background-image", "url(images/right.png)");
$(this).animate({width: 100}, 350);
}
else{
$(this).css("background-image", "url(images/left.png)");
$(this).animate({width: 25}, 350);
}
})