gpt4 book ai didi

jQuery 语法问题 - css 和多背景定位

转载 作者:行者123 更新时间:2023-11-28 13:16:09 25 4
gpt4 key购买 nike

我正在尝试调整 <body> 上两个背景之一的背景位置使用 CSS3 的多背景属性。我需要用 jQuery 更新一个位置,但我很困惑!我在一个变量中有一个整数,但它不起作用,我认为我的串联是错误的...

$('body.home').css( "background-position" , 
"top center, center" + bottomBackgroundOffset );

我还需要某种监听器(我认为这是正确的术语),以便在窗口大小发生变化时触发此代码,这是因为背景图像需要更新它的位置。不要问我为什么要这样做,这是不得已的办法..!

最佳答案

对于 resize() 做:

$(window).resize(function() { 
$('body.home').css( "background-position" , "top center, center " + bottomBackgroundOffset + "px" );
});

当然你需要先设置你的 var bottomBackgroundOffset;,我假设你已经在做。

参见 API Doc了解更多信息。

关于jQuery 语法问题 - css 和多背景定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15011294/

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