我已經實現了一些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 -->
對我來說很好。主頁圖像被立即加載。問題可能是由於圖像大小或文件大小。嘗試保存爲網絡優化的圖像。我注意到內頁上的圖像加載非常塊。我正在使用Firefox。 – floor 2015-03-02 20:43:29
你的腳本看起來不錯,但找不到bg-12.gif。 – 2015-03-02 20:44:31
你確定圖像大小會導致它加載塊或根本沒有?它不會只是在加載時推遲嗎? – 2015-03-03 14:34:12