我试图用jQuery在悬停时更改div的背景图像.这是我到目前为止所提出的,然而,它不起作用:
HTML
<div class="logo"></div>
Run Code Online (Sandbox Code Playgroud)
CSS
.logo {
width: 300px;
height: 100px;
background: url('http://placehold.it/300x100/ffffff/000000.png&text=first') no-repeat center top;
}
Run Code Online (Sandbox Code Playgroud)
JS
$('.logo').hover(
function(){
$(this).animate({backgroundImage: 'http://placehold.it/300x100/ffffff/000000.png&text=second'},'fast');
},
function(){
$(this).animate({backgroundImage: 'http://placehold.it/300x100/ffffff/000000.png&text=first'},'fast');
});
Run Code Online (Sandbox Code Playgroud)
jsfiddle:http://jsfiddle.net/26j6P/1/
我究竟做错了什么?如果我为背景颜色设置动画,它就可以正常工作......