小编Iul*_*ita的帖子

jQuery在悬停时改变(使用淡入淡出动画)div的背景图像

我试图用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/

我究竟做错了什么?如果我为背景颜色设置动画,它就可以正常工作......

html css jquery jquery-ui jquery-animate

6
推荐指数
2
解决办法
5万
查看次数

标签 统计

css ×1

html ×1

jquery ×1

jquery-animate ×1

jquery-ui ×1