php - 随机背景图片导致登陆页面显示问题?

标签 php html css

我已经实现了一些 PHP 和 CSS 代码来为着陆页选择随机背景图片。当您第一次访问该页面时,会出现加载问题,例如背景图像没有出现,或者只有部分背景图像出现(在实际内容下方)。这发生在设备上的所有平台上。

当我点击刷新时,图像开始正确显示,但在第一次或两次刷新之前它们不会显示。

感谢您的帮助。您可以在此处查看该页面:

http://agentboris.com/

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 &#183; Real Estate Broker &#183; 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 -->

最佳答案

这是因为您的某些图片在服务器上找不到,例如:

http://agentboris.com/backgrounds/bg-12.gif

我在 Chrome 中加载的其他一切都很好。

关于php - 随机背景图片导致登陆页面显示问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28819031/

相关文章:

php - Cron 作业的远程地址问题

php - mysql数据存在代码不起作用

javascript - 从字符串中删除样式属性

javascript - 隐藏 div 中的 Google map

javascript - JQuery scroll()/scrollTop() 在 IE 或 Firefox 中不工作

php - 如果用户使用 php 登录,如何仅使页面可访问

html - 悬停在与 wrapper 相同的背景颜色上

jquery - 当文本溢出时使 JQuery Marquee

JavaScript/HTML : How do I display an IMG with a set dimension and if the image is wider or taller than that dimension, 裁剪/ overflow hidden ?

php - 搜索文本以找到相似之处