How do I convert a CSS background-position property from percentages into pixels?

蹲街弑〆低调 提交于 2019-12-05 16:01:04

In the future this will be possible using CSS3's calc function. But since that's not widely supported right now, below is a more practical solution.

Simply use the incremental notation jQuery supports for these properties. For example

$(some-element).css({ "background-position": "+=10px" });

This syntax was supported by $.animate before it was supported by $.css, but recent versions of jQuery support it in both cases.

Here's a jsfiddle demonstrating it in action.

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