私のコードがホバー時に要素を「不透明度:1」に設定せず、要素を回転させる理由を探していました。html と js は以下のとおりです。
要素が選択されていない (rwunselected クラスを持っている) 場合、ホバー時に機能を実行する必要があるという考え。
<table cellpadding="0" cellspacing="10">
<tr>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/cellists.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/elegance.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/musicrooms.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/absolution.png" border="0" /></td>
</tr>
<tr>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/helpmankind.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/liva.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/anthonybrown.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/blairjohnstone.png" border="0" /></td>
</tr>
<tr>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/questiventi.png" border="0" /></td>
<td width="135" align="center"><img class="recentworkitem rwunselected" src="images/recentwork/smallimages/surveycentre.png" border="0" /></td>
</tr>
</table>
JavaScript
//set opacities
$('.recentworkitem').css('opacity','.15');
//hover effect on all items with class recentworkitem
$('.recentworkitem').hover(function(){
if($(this).hasClass('rwunselected')){
$(this).stop().animate({opacity:'1'},{duration:300})
$(this).stop().rotate({animateTo:-90, duration:300})
}
},
function(){
if($(this).hasClass('rwunselected')){
$(this).stop().animate({opacity:'.15'},{duration:300})
$(this).stop().rotate({animateTo:0, duration:300})
}
});
//click function
$('.rwunselected').click(function(){
//swap image opacities and classes
$(this).removeClass('rwunselected');
$(this).animate({opacity:'1'},{duration:300});
$('.rwselected').addClass('rwunselected');
$('.rwselected').animate({opacity:'.15'},{duration:300});
$('.rwselected').removeClass('rwselected');
$(this).addClass('rwselected');
//rotate the old selected item back to 0 degrees
$('.rwunselected').rotate({animateTo:0, duration:300})
});