我明白了here jquery 1.5.0 中缺少 backgroundPosition
动画是一个已知错误。还没解决吗?
查看此jsfiddle ,在 jquery 1.4.4 中使用 backgroundPosition
动画,然后看看这个 one ,并发现即使在 jquery 1.7.1 中它也不起作用。
知道他们什么时候能解决这个问题吗?
我很想知道,因为我刚刚在 Chrome 控制台中看到一条警告,内容如下:
event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.
我担心我会继续使用 jquery 1.4.4 来实现动画功能,但 Chrome 会在下一次更新中取消该功能。
更新
公认的答案,即使用background-position-x和y的想法不适用于Firefox。现在我必须回到 1.4.4,直到找到更好的解决方案。
最佳答案
您需要分别指定background-position-x
和-y
,如下所示:
$('div').animate({
'background-position-x': '-6000px', 'background-position-y': '-200px' }, 4000);
<强> Working example. (jQuery 1.7.1)
顺便说一句,由于您的 background-position-y
没有改变,您可以简单地省略该额外的行并仅更改您的 -x
。
关于jquery - 为什么我无法在 jquery 1.4.4 之后设置背景位置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8663596/