您不能为背景图像的不透明度设置动画。这是不可能的。解决方法是将<img>
一个parent container
<div id="2">
情景->
<div id="1">
div 1
</div>
<div id="wrapper">
<img src="path/to/my/background/image"/>
<div id="2">
</div>
</div>
相对的 css ->
#wrapper{
position:relative;
}
#wrapper img{
position:absolute;
top:0;
left:0;
z-index:-1
}
#wrapper #div2{
display:block;
height: // this value should be the same as the background images size.
width: // this value should be the same as the background images size.
}
jQuery ->
$('#div1').hover(function(){
$('#wrapper img').fadeOut('slow', function(){
//this is the callback function of fadeout, now change the background image URL.
$(this).css('background-image', 'location/to/my/new/image.ext');
var checkForDelay = setTimeout(function(){
//if they haven't moused out after 3 seconds, then show them the new background.
$('#wrapper img').fadeIn('slow');
}, 3000);
});
}, function(){
clearTimeout(checkForDelay);
$('#wrapper img').fadeIn('slow');
});
jsFiddle 概述了类似的原则