我希望得到這個隨機背景圖像的編碼工作:http://css-tricks.com/snippets/php/randomize-background-image/有麻煩實施隨機背景圖像
我仔細檢查過的文件名,路徑,所有代碼和指令。我覺得有些事我不明白。
您可以在這裏看到的頁面: http://agentboris.com/newwebsite/index.html
感謝您的幫助。
我希望得到這個隨機背景圖像的編碼工作:http://css-tricks.com/snippets/php/randomize-background-image/有麻煩實施隨機背景圖像
我仔細檢查過的文件名,路徑,所有代碼和指令。我覺得有些事我不明白。
您可以在這裏看到的頁面: http://agentboris.com/newwebsite/index.html
感謝您的幫助。
您在http://agentboris.com/newwebsite/index.html的文件位於.html,它應該在.php中,因爲您可以使用教程中的php代碼。
這個簡單的代碼嘗試(不要忘記保存您的索引文件作爲PHP擴展):
<?php
$bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.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
?>
<!DOCTYPE html>
<html>
<head>
<title>Tests purposes</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<style type="text/css">
<!--
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
-->
</style>
</head>
<body>
</body>
</html>
工作就像一個魅力,非常感謝! – 2015-02-24 15:58:06
您的歡迎:) – lmarcelocc 2015-02-24 15:58:28
使你的文件轉換爲.php或調用PHP腳本使用JavaScript/jQuery的 – AlexG 2015-02-24 15:56:22