0

其实我想为背景图像设置动画。所以我所做的是,当 div 悬停时,背景图像逐渐隐藏。

$(this).animate({ backgroundSize: '0%', opacity: 0}, 500)

现在当 div 没有悬停时,我想将 backgroundSize 设置为默认值.. 像

$(this).animate({backgroundSize: 'auto', opacity: 1}, 500)

但它没有用。

在 Css div 类中就像...

.divImg{ background: url(../imgs/bgImg.png) no-repeat center; background-size: auto }

我想要的是当 div 没有悬停时,背景图像应该回到它的默认大小和位置。

4

2 回答 2

0

尝试添加!important

  $(this).animate({backgroundSize: 'auto !important', opacity: 1}, 500)

编辑:更新代码以匹配问题中的示例。

于 2013-04-18T21:46:59.997 回答
0

i am not 100% sure abut this, but i believe jquery .animate() can only animate number based properties. my guess is that trying to make "100%" change to 'auto' might be the problem.

try only animating the opacity, and change to 'auto' with the .css() function, after a timeout, if you need it.

于 2013-07-02T17:14:03.670 回答