【发布时间】:2013-09-16 13:15:58
【问题描述】:
我正在尝试使用 jQuery 更改悬停时 div 的背景图像。 到目前为止,这是我想出的,但是,它不起作用:
html
<div class="logo"></div>
css
.logo {
width: 300px;
height: 100px;
background: url('http://placehold.it/300x100/ffffff/000000.png&text=first') no-repeat center top;
}
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');
});
jsfiddle在这里:http://jsfiddle.net/26j6P/1/
我做错了什么? 如果我为背景颜色设置动画,它就可以正常工作...
【问题讨论】:
-
jQuery 的动画不适用于图像。您需要使用 css 和转换才能使其正常工作。
-
如果你真的想使用 jQuery,最好只在 css 中悬停 .logo:hover {/*new img */}动画
-
感谢您的提醒。我从没想过 jQuery 的动画不适用于图像...
标签: jquery html css jquery-ui jquery-animate