Why can't I animate backgroundPosition past jquery 1.4.4?

落爺英雄遲暮 提交于 2020-01-04 02:16:10

问题


I see here that the lack of backgroundPosition animation in jquery 1.5.0 is a known bug. Has it still not been fixed?

See this jsfiddle, with backgroundPosition animating in jquery 1.4.4, and then look at this one, and see that it isn't working even in jquery 1.7.1.

Any idea when they're going to fix this?

I'm wondering because I just saw a warning in my Chrome console saying this:

event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.

I'm worried that I'm going to continue to use jquery 1.4.4 for the animating functionality, but then Chrome will pull the functionality in the next update.

UPDATE

The accepted answer, the idea to use background-position-x and y doesn't work with Firefox. For now I'm going to have to go back to 1.4.4, until I find a better solution.


回答1:


You need to specify background-position-x and -y separately like so:

$('div').animate({
  'background-position-x': '-6000px', 'background-position-y': '-200px' }, 4000);

Working example. (jQuery 1.7.1)

As a side note, since your background-position-y isn't changing, you can simply omit that extra line and just change your -x.




回答2:


I had the same issue here: "puff of smoke" effect javascript sprite animation

It seems newer versions of jQuery above 1.4.4 enable smooth background scrolling effects at a cost of breaking sprite animations that are in fact jerky relying on persistence of vision. I'd say the animate function was not intended for this, but it just worked (TM) back then.

To make my background-position sprite animation I wrote a function using setTimeout

http://jsfiddle.net/Y7Ek4/22/

It's more low level but it isn't a lot more code at all.



来源:https://stackoverflow.com/questions/8663596/why-cant-i-animate-backgroundposition-past-jquery-1-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!