我一直在寻找为什么我的代码不会在悬停时将元素设置为 'opacity: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})
});