Switch opacity to other divs

I was looking for a simple way, possibly with jQuery, to lower the opacity of all the other DIVs on hover and bring them back.

<div id="fade_container">
     <div id="fade1">Content</div>
     <div id="fade2">Content</div>
     <div id="fade3">Content</div>
     <div id="fade4">Content</div>
</div>

For example: When fade2 is hovering fade1 , fade3 and fade4 should lose some opacity.

Any help would be appreciated

Thanks!

+2
source share
4 answers

http://api.jquery.com/fadeTo/

$('#fade_container div').hover(function(){  // mouseover 
  $(this).siblings().fadeTo('fast',0.5);  
}, function(){  // mouseout 
  $(this).siblings().fadeTo('fast',1.0);
});

http://jsfiddle.net/6XygU/4/

+3
source

CSS

.faded {
    opacity:0.5;
}

JQuery

$('#fade_container div').hover(function(){
    $(this).siblings().addClass('faded');
},function(){
    $(this).siblings().removeClass('faded');
});
+1
source

jquery effects library.. , .

0

- ?

$('div', '#fade_container').hover(function(){
   $('div', '#fade_container').not(this).stop().animate({
     opacity: .2
   }, 500);

   $(this).stop().animate({
     opacity: 1
   }, 500);
});

: http://jsfiddle.net/Sj8x5/1/

0

Source: https://habr.com/ru/post/1621703/


All Articles