jQuery の場合:
シナリオ ** - ホバー効果を持つ 4 つの 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;
});
});