如何将 background-position
从其原始位置偏移,比方说 20px?
喜欢:
$(".selector").animate("slow").css("backgroundPosition", "center -=20px");
(这显然行不通......但我该怎么做??)
最佳答案
默认情况下,jQuery 不会为背景设置动画。有这个short code可以做到这一点。添加它之后,您的代码应该可以工作,但首先要像这样修复它:
$(".selector").animate({ "backgroundPosition": "center -=20px" },"slow");
取自:
http://snook.ca/archives/javascript/jquery-bg-image-animations
演示:
关于javascript - 背景位置 +/- X 像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7505497/