我已经实现了一些 PHP 和 CSS 代码来为着陆页选择随机背景图片。当您第一次访问该页面时,会出现加载问题,例如背景图像没有出现,或者只有部分背景图像出现(在实际内容下方)。这发生在设备上的所有平台上。
当我点击刷新时,图像开始正确显示,但在第一次或两次刷新之前它们不会显示。
感谢您的帮助。您可以在此处查看该页面:
HTML:
<?php
$bg = array('bg-01.gif', 'bg-02.gif', 'bg-03.gif', 'bg-04.gif', 'bg-05.gif', 'bg-06.gif', 'bg-07.gif', 'bg-08.gif', 'bg-09.gif', 'bg-10.gif', 'bg-11.gif', 'bg-12.gif', ); // 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
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1100">
<title>Boris Kholodov · Real Estate Broker · Toronto, Canada</title>
<meta name="description" content="List your property with Boris Kholodov, the Number 1 real etsate broker in downtown and central Toronto by number of units sold in 2014.">
<link rel="stylesheet" type="text/css" href="design.css">
<!-- BACKGROUND IMAGES -->
<style type="text/css">
<!--
body{
background: url(backgrounds/<?php echo $selectedBg;?>) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
-->
</style>
<!-- BACKGROUND IMAGES -->
最佳答案
关于php - 随机背景图片导致登陆页面显示问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28819031/