Javascript jQuery backgroundPosition不接受多个值?
我试图使用变量作为坐标来设置身体背景图像中的运动动画,但jquery的backgroundPosition似乎只接受一个值。我尝试了一些方法,比如backgroundPosition:distance1+“”+distance2和backgroundPosition:distance1+“-50px”(我希望它在整个时间都是这个值),但即使我在CSS中设置了最大值,它也默认使用我的第一个值(左)来处理这两个值。任何帮助都将不胜感激Javascript jQuery backgroundPosition不接受多个值?,javascript,jquery,css,Javascript,Jquery,Css,我试图使用变量作为坐标来设置身体背景图像中的运动动画,但jquery的backgroundPosition似乎只接受一个值。我尝试了一些方法,比如backgroundPosition:distance1+“”+distance2和backgroundPosition:distance1+“-50px”(我希望它在整个时间都是这个值),但即使我在CSS中设置了最大值,它也默认使用我的第一个值(左)来处理这两个值。任何帮助都将不胜感激 function shiftBoxes(distance1, d
function shiftBoxes(distance1, distance2, id){
activeBtn('pos' + id.substring(4));
$("#boxMover").animate({
marginLeft: distance1
}, 500, function() {});
$(document.body).animate({
backgroundPosition: distance2
}, 500, function() {});
}
//Add one of these for every box
//The distance to move to the next box is always -1804(*("#pos" + n) - 1) pixels
$("#pos1").click(function() {
shiftBoxes('0', '-1400', '#box1');
});
$("#pos2").click(function() {
shiftBoxes('-1804', '-1200', '#box2');
});
$("#pos3").click(function() {
shiftBoxes('-3608', '-1000', '#box3');
});
我找到了。看起来您需要围绕以下值设置参数:
.animate({backgroundPosition:(-20px 94px)”}
属性backgroundPosition accpets值如下:
左上角
右下角
中间偏左
或
x%Y%,其中左上角为0%0%,右下角为100%100%
或
XPOSYPO,您可以使用任何css单位,如%、像素、em等
最后
继承
要使用它,您可能需要一些类似于:
.style.backgroundPosition="center bottom";
or
.style.backgroundPosition = "20% 50%";
我希望这有帮助。和平