gpt4 book ai didi

javascript - jQuery backgroundPosition 不接受多个值?

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:36 24 4
gpt4 key购买 nike

我正在尝试使用变量作为坐标在我 body 的背景图像中设置动画,但 jquery 的 backgroundPosition 似乎只接受一个值。我尝试了一些东西,比如 backgroundPosition: distance1 + ""+ distance2, and backgroundPosition: distance1 + "-50px"(我希望它一直保持的值),但即使我在 CSS 中设置了最高值,它只是默认为两者都使用我的第一个值(左)。任何帮助将不胜感激!

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');
});

最佳答案

我找到了 this example .看起来您需要像这样围绕值进行括号:

.animate({backgroundPosition:"(-20px 94px)"}

关于javascript - jQuery backgroundPosition 不接受多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6296510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com