开发者

Toggle Opacity on other DIVs

I was looking for a simple way, probably with jQuery, of lowering the opacity of all other DIVs when hovered and returning them back in on out.

<div i开发者_开发技巧d="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 hovered fade1, fade3 and fade4 should lose some opacity.

Any help would be appreciated,

Thanks!


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/


CSS:

.faded {
    opacity:0.5;
}

JQuery:

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


have you tried looking at jquery effects library.. this library does exactly what you are looking for.


How about something like this?

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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜