jQuery addClass fadeIn fadeOut
$('.a').bind('mouseover',function(){
$('.a').addClass("b");
}).bind('mou开发者_开发技巧seout',function(){
$('.a').removeClass("b");
});
I want to add fadeIn fadeOut in the above code like :
$('.a').bind('mouseover',function(){
$('.a').addClass("b").fadeIn('slow');
}).bind('mouseout',function(){
$('.a').removeClass("b").fadeOut('fast');
});
But that doesn't work for me...tried to google but that didn't work either.
Your code is working as in bug-free but consider this:
fadeOut
hides the element and you won't be able to hover over it again.fadeIn
on an already visible element won't do anything.
Firstly, I think your fadeOut
and fadeIn
are the wrong way around.
You can't fade something in on mouseover
, because the fact you are fading it in implies it isn't visible in the first place, hence you can't mouseover
it.
Assuming this is the case, and you switch them around, this leads to a second problem, once it's faded out mouseout
will automatically fire because the mouse is no longer over the element because the element isn't visible (you've just faded it out).
Can you confirm which effect you are looking for? There may be an alternative.
精彩评论