views:

79

answers:

3

I have a filter running on a set of list elements which fades the lesser desirable elements down to 0.25 opacity but I'd love to have their opacity return to 1 and then back down to 0.25 on hover over and out. Is this fairly simple to do?

I'm only having trouble finding a way to grab the selected element's current opacity so I can store it in a variable for use.

$('#centerPanel li').hover(function(){
        var currentOpacity = $(this).?????
        $(this).fadeTo(1,1);
    },
    function(){
        $(this).fadeTo(1,currentOpacity);
    });
A: 

Try $(this).css("opacity")

source

Jeriko
A: 
$('#centerPanel li').hover(function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
},
function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
});
jAndy
This doesn't actually answer the question "can you find the selected element's opacity with jQuery"... I didn't -1 you though.
Jeriko
+1 - While not answering the question directly, it is related to setting opacity of the selected element. In other words your example illustrates a good point.
David Robbins
@Jeriko: Don't you think, if an answer differs a little bit from the exact question but is a better solution for the basic problem, should also be mentioned ?
jAndy
I totally agree jAndy, which is why I didn't -1 you. I've just noticed more and more that people aren't always looking to be corrected; they just want advice in the scope of their question. If you had first answered him and then suggested a better way to go about it, you would have had a great answer :)
Jeriko
+1  A: 

You need to set the mouseout opacity var outside the function, this will prevent your function to change that value.

nohoverOpacity = $('#centerPanel li').css("opacity");
hoverOpacity = 1;
dur = 1000;
$('#centerPanel li').hover(function(){
        $(this).fadeTo(dur,hoverOpacity);
    },function(){
        $(this).fadeTo(dur,nohoverOpacity);
});

Is this what you want? :)

CuSS