views:

159

answers:

3

Say you have a bunch of elements on a webpage you don't use much, how can jQuery fade them a little, but only when there is no mouseover? It must fade back on mouseover!

A: 

if you dont need the animation stuff you can do this with pure css by using the :hover psoudo selector however there is also a .hover() method in jquery, it will help you to achieve this effect. something like this: $('.my_less_used_divs').hover(fadeInFunction, fadeOutFunction);

antpaw
that's a cool approach too
Luke Stanley
+1  A: 

I solved it like this:

//list the items you want to fade out in normal selector format
var arr = [ "#navTop","#banner","#idViewToolbar","#fbsidebar","#idActionP","table.noBorder" ];


//delay function by Clint Helfers
$.fn.delay = function( time, name ) {

    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );

};

$.each( arr, function(i, l){
   jQuery(l).fadeTo(600, 0.10);
   jQuery(l).mouseenter(function(){
        jQuery(this).fadeTo(600, 1);
    });

       jQuery(l).mouseleave(function(){
        jQuery(this).delay(5000).fadeTo(600, 0.10);
    });

 });

I actually used it for FogBugz - they have a plugin that lets you insert your own CSS + Javascript into the page, I use it to fade out most stuff but the bug/feature list I'm working on.

Luke Stanley
A: 

To actually put what antpaw recommended into code. Do the following.

$(".my_less_used_divs").hover(function() {
    $(this).css("opacity", 1);
}, function() {
    $(this).css("opacity", .5);
}).css("opacity", .5);

You should give antpaw the accepted answer if you like this.

jessegavin
cool. though it's not fading or a list.
Luke Stanley