Reputation: 13
I am a bit stuck with this one. Here is a basic outline of my setup:
<div id="shell">
<div class="subelement">One</div>
<div class="subelement">One</div>
<div class="subelement">One</div>
<div class="subelement">One</div>
</div>
I'm looking to, on the hover of .subelement, decrease the opacity of the remaining divs with subelement class. I am aware of how to use hover effects with jQuery, just don't know where to start when it comes to animating the remaining divs that are not being hovered over. Thanks any for suggestions.
Update: Final Solution - http://jsfiddle.net/yqPFH/
Upvotes: 0
Views: 935
Reputation: 21
Two-part question:
1) How do you keep only the first line with opacity:1 and rest at .5 2) Once selected or hovered, how do you keep the opacity:1, UNTIL you hover/select another line?
Upvotes: 0
Reputation: 11348
While this question already has an answer, an additional answer was provided that I tweaked and has since been deleted. Here it is using jQuery and loses the hover state when nothing is hovered. Easy.
$(".subelement").hover( function() {
$(this).siblings().stop().fadeTo("fast", 0.5);
}, function() {
$(this).siblings().stop().fadeTo("fast", 1.0);
});
Upvotes: 1
Reputation: 157334
I would've used CSS instead
HTML
<div id="shell">
<div class="subelement">One</div>
<div class="subelement">One</div>
<div class="subelement">One</div>
<div class="subelement">One</div>
</div>
CSS
#shell:hover {
color: rgba(0,0,0,.5);
}
.subelement:hover {
color: rgba(0,0,0,1);
}
Upvotes: 4
Reputation: 222158
$("#shell .subelement").hover(function() {
$(this).css("opacity", 1).siblings().css("opacity", 0.6);
});
Upvotes: 1