在 jQuery 中:
场景 ** - 我有四个具有悬停效果的 Div。- 全部使用 jquery 动画移动 backgroundPosition 以显示悬停状态。
问题** - 我想设置焦点或点击状态,这样一旦你点击了一个按钮,它就会进一步动画背景位置以显示新状态。我还希望这些按钮知道是否单击了任何其他按钮并删除当前的单击状态并开始在新选择的按钮上为新的单击状态设置动画...??
我的努力** - 我做了一些编码,但似乎无法解决这个焦点状态,再次提前感谢!;)
HTML **
<div class="rollOversHolderOne">
<div id="mainServices_01" class="rollOver_1 rollover"></div>
<div id="mainServices_02" class="rollOver_2 rollover"></div>
<div id="mainServices_03" class="rollOver_3 rollover"></div>
<div id="mainServices_04" class="rollOver_4 rollover"></div>
</div>
CSS **
#mainServices_01 {
width:103px;
height:131px;
float:left;
background:url(../images/slideHover.png) repeat 0 0;
background-position: inline;
}
#mainServices_02 {
width:103px;
height:131px;
float:left;
background:url(../images/slideHover.png) repeat 0 0;
background-position: inline;
}
#mainServices_03 {
width:103px;
height:131px;
float:left;
background:url(../images/slideHover.png) repeat 0 0;
background-position: inline;
}
#mainServices_04 {
width:103px;
height:131px;
float:left;
background:url(../images/slideHover.png) repeat 0 0;
background-position: inline;
}
jQuery **
jQuery(document).ready(function(){
var flag;
var active;
jQuery('.rollover').css( {backgroundPosition: "0 0"} ).click(function(){
flag = false;
jQuery(this).stop().animate(
{backgroundPosition:"(0 -130.5px)"},
{duration:1});
});
jQuery('.rollover').mouseout(function(){
if(flag == false)
{
jQuery(this).stop().animate(
{backgroundPosition:"(0 -130.5px)"},
{duration:1})
}else{
jQuery(this).stop().animate(
{backgroundPosition:"(0 0)"},
{duration:1})
}
});
jQuery('.rollover').mouseover(function(){
jQuery(this).stop().animate(
{backgroundPosition:"(0 -130.5px)"},
{duration:1})
flag = true;
});
});