问题
I currently have a div with a image overlaid that I am currently using the following code to fadeout the image to show the text in the element underneath:
$(".Content_Frame_Image").hover(
function() {
$(this).stop().animate({"opacity": "0"}, "slow");
},
function() {
$(this).stop().animate({"opacity": "1"}, "slow");
});
However because im only making it invisible I cant get the links to work underneath, you can see a sample here http://playing.everythingcreative.co.uk
If I use the fadeout method then it wont fadein on hover...
回答1:
what's about:
$(".Content_Frame_Container")
.each(function(){
$(this).find('.Content_Frame_Image');
})
.hover(
function(){
$(this).find('.Content_Frame_Image').stop().fadeOut('slow');
},
function(){
$(this).find('.Content_Frame_Image').stop().fadeIn('slow');
}
);
tested it with chrome dev-tools -- should work nicely.
回答2:
If you need to use opacity instead of fadeOut, a callback function after your animation:
$(".Content_Frame_Image").hover(
function() {
$(this).stop().animate({"opacity": "0"}, "slow", function() {
//move the element off-screen
$(this).css({
'position' : 'absolute',
'left' : '-9999px'
});
});
},
function() {
//move it back first
$(this).css({
'position' : 'absolute',
'left' : '0'
});
$(this).stop().animate({"opacity": "1"}, "slow");
});
来源:https://stackoverflow.com/questions/12148702/fadeout-fadein-image-over-element