我想使用悬停功能更改按钮的背景图像 y 位置。有没有一种简单的方法来保持 xpos 或者我应该先获得位置,将其拆分并再次与 $.css() 一起使用。
如果有人悬停其中任何一个,我应该更改所有 3 个跨度的背景位置。所以 bt_first:hover 似乎不可用。
这是我的用法。我写了#should stay same#来放置我不想改变xpos的值:
$('.bt_first,.bt_sec,.bt_third').hover(function(){
$('.bt_first,.bt_sec,.bt_third').css({'background-position':'#should stay same# -150px'})
},function(){
$('.bt_first,.bt_sec,.bt_third').css({'background-position':'#should stay same# -110px'});
});
这是我的html。:
<div><a id="add_comment_btn"><span class="bt_first comments_t"><span> </span></span><span class="bt_sec"> </span><span class="bt_third">Comments</span></a></div>
和CSS:
.bt_first,.bt_sec,.bt_third,.logout_t,.comments_t span {
background: url('img/toolbar_bckrnd.png') no-repeat;
}
.bt_first {
background-position: left -110px;
display: inline-block;
height: 24px;
width: 15px;
}
.bt_sec {
background-position: -149px -110px;
display: inline-block;
height: 24px;
width: 2px;
}
.bt_third {
background-position: right -110px;
display: inline-block;
height: 24px;
padding: 0 10px;
}