JQuery selectors in the <li> list
Can someone advise me with jQuery selectors.
I have an HTML list (see below) with four flag images in it. When the user flips a flag, for example, italy, I want him to reduce all the other three flags to 50% opacity.
<ul id="flags">
<li id="German"><img src="images/flag_german.jpg" /></li>
<li id="Italian"><img src="images/flag_italian.jpg" /></li>
<li id="Spanish"><img src="images/flag_spanish.jpg" /></li>
<li id="French"><img src="images/flag_french.jpg" /></li>
</ul>
+3
Decbrad
source
share4 answers
Try the following:
$(function() {
$('#flags li').hover(function() {
$(this).siblings().stop(true).animate({opacity:'0.5'},1000);
}, function() {
$(this).siblings().stop(true).animate({opacity:'1'},1000);
});
});
By using stop, you help prevent a state in which you rolled many elements and they animated the animation in the queue. It clears all current animations in the queue for the item and assigns a new one.
, , fadeIn fadeOut, fadeIn/fadeOut hover. , .
+11