gpt4 book ai didi

javascript - 带有背景覆盖的随机背景?

转载 作者:行者123 更新时间:2023-11-28 02:46:04 25 4
gpt4 key购买 nike

您好,我正在尝试使用叠加层随机化我的网站背景,但我在显示随机化背景时遇到了问题。

这就是我的工作

.css/.php

#intro {
background:
/* top, transparent black gradient */
linear-gradient(
rgba(0, 0, 0, 0.7),
rgba(0, 0, 0, 0.7)

),
/* bottom, image */

url(/images/<?php echo $selectedBg; ?>);
background-size: 100% auto, cover;
background-attachment: fixed, fixed;
background-position: top left, bottom center;
background-repeat: repeat, no-repeat;
width: 100%;
height: auto;


}
<?php
$bg = array('bg-01.png', 'bg-02.jpg' ); // array of filenames

$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>

我已经检查了 bg-01.png、bg-02.jpg 的文件名并且是正确的。如果我做错了什么,将不胜感激。

最佳答案

将css和php代码放在一个文件中,在css之后先加载php代码

<?php
$bg = array('bg-01.png', 'bg-02.jpg' ); // array of filenames

$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>

<style>
#intro {
background:
/* top, transparent black gradient */
linear-gradient(
rgba(0, 0, 0, 0.7),
rgba(0, 0, 0, 0.7)

),
/* bottom, image */

url(/images/<?php echo $selectedBg; ?>);
background-size: 100% auto, cover;
background-attachment: fixed, fixed;
background-position: top left, bottom center;
background-repeat: repeat, no-repeat;
width: 100%;
height: auto;


}

</style>

关于javascript - 带有背景覆盖的随机背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528810/

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