jQuery.animate background-position

不羁的心 提交于 2019-12-01 13:16:48

I had this same problem. The plugin linked by Samich is the only way to hit both birds with one stone (animate in nearly all browsers with nothing but JQuery/Javascript).

Here's an alternative, but it ideally uses a feature-detection script like Modernizr for compatibility:

Use JQuery's .animate() and background-position-x 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/

As I know jQuery doesn't have ability to animate background. But it's possible with plugins:

http://plugins.jquery.com/project/backgroundPosition-Effect

http://www.protofunc.com/scripts/jquery/backgroundPosition/

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