Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在此代码中固定我的背景?_Javascript_Html_Background_Fixed - Fatal编程技术网

Javascript 如何在此代码中固定我的背景?

Javascript 如何在此代码中固定我的背景?,javascript,html,background,fixed,Javascript,Html,Background,Fixed,在这个特定的代码中,我如何使我的背景固定,使其不会滚动 我已经试过body.setAttribute(“backgroundAttachment”,“fixed”);,但它不起作用 Igor的最终答案 var images=[“bf1.jpg”、“fifa17.jpg”、“rocketleague.jpg”、“civ6.jpg”、“infinitewarfare.png”]; 函数getRandomArbital(min,max){返回Math.floor(Math.random()*(m

在这个特定的代码中,我如何使我的背景固定,使其不会滚动

我已经试过body.setAttribute(“backgroundAttachment”,“fixed”);,但它不起作用


Igor的最终答案


var images=[“bf1.jpg”、“fifa17.jpg”、“rocketleague.jpg”、“civ6.jpg”、“infinitewarfare.png”];
函数getRandomArbital(min,max){返回Math.floor(Math.random()*(max-min)+min)}
123
document.body.setAttribute(“样式”,“背景图像:url(“+图像[GetRandomArbital(0,5)]+”)”);背景重复:无重复;背景位置:中间顶部;背景附件:固定;背景大小:封面;宽度:;显示:;颜色:红色;”/*从0到4*/;

为什么要投反对票?它只是一个question@KevinKloet我无法在此代码中使用它。您的代码中有很多错误,请使用正确的代码创建代码片段或JSFIDLE。感谢您将此问题标记为已解决。为此,请单击您认为最有帮助的答案旁边的勾号,使其变为绿色。我们不会编辑标题以在此处添加[已解决]标记。谢谢