jQuery 1.6: backgroundPosition vs backgroundPositionX and FF4 compatibility

允我心安 提交于 2019-11-27 09:39:05
Lucy Lou

Firstly, JQuery is unable to animate two values at the same time, thus you saw that inputting two values for backgroundPosition did not work at all. Also note that for px values, the JQuery documentation encourages you to not write the px.

Secondly, backgroundPositionX and backgroundPositionY are non-standard CSS properties only supported in a few browsers, most notably IE and recently Webkit, which is why you will find it does not work in FF or Opera. (See here.)

I have found that mixing JQuery's animate and CSS transitions works to animate a background image on one axis in most browsers. I will quote from my answer to another question ( jQuery.animate background-position):

Use JQuery's .animate() and backgroundPositionX and Y separately for IE (this will work with the latest JQuery). Then in browsers that support CSS transitions (nearly everything besides IE), use .css() instead of .animate() to change the background position and set a CSS transition in your stylesheet.

You'll be covering most browsers with the above, but it may not be AS compatible as just using a plugin. See it at work here: http://jsfiddle.net/lucylou/dVpjh/

According to: http://www.w3schools.com/css/pr_background-position.asp

"If you only specify one value, the other value will be 50%. You can mix % and positions"

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