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).?????
开发者_Go百科 $(this).fadeTo(1,1);
},
function(){
$(this).fadeTo(1,currentOpacity);
});
Try $(this).css("opacity")
source
there are complete guide "Get Current Opacity in MSIE using jQuery" http://zenverse.net/get-current-opacity-in-msie-using-jquery-cross-browser-codes/
code:
function getopacity(elem) {
var ori = $(elem).css('opacity');
var ori2 = $(elem).css('filter');
if (ori2) {
ori2 = parseInt( ori2.replace(')','').replace('alpha(opacity=','') ) / 100;
if (!isNaN(ori2) && ori2 != '') {
ori = ori2;
}
}
return ori;
}
//to use it
var currentopacity = getopacity('div.the-element');
$('#centerPanel li').hover(function(){
if(!$(this).is(':animated'))
$(this).animate({opacity: 'toggle'}, 1000);
},
function(){
if(!$(this).is(':animated'))
$(this).animate({opacity: 'toggle'}, 1000);
});
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? :)
精彩评论