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!
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.