我想用悬浮功能改变按钮的背景图像y位置。有没有简单的方法来保持xpos或者我应该先获取位置,然后再次使用$ .css()重新分割并再次使用。通过jquery改变背景图像的位置
如果有人悬停其中任何一个,我应该更改所有3个span的背景位置。所以bt_first:悬停似乎不可用。
这是我的用法。我写#should留相同#来,我不想改变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;
}
类似:http://stackoverflow.com/questions/2117594/adding-金额对背景位置点击jquery – thirtydot 2011-02-04 16:18:10
@thirtydot我不认为它是相同的。我只想改变3个不同类的ypos。 xpos应该保持预定义。你的文章谈论别的东西。我错了吗?不管怎么说,还是要谢谢你。 – Kemal 2011-02-04 16:21:01