[Blog 大補帖:佈景圖片] 拋開一成不變,佈景圖片隨機更新之語法

本站網誌的佈景主題是採用 HKSS, UCLA Design by leison Skin,

layout.css 樣式表中的
#mainContent-topimg{
                background-image: url(content_bg.jpg);

attachments/200807/4935469675.jpg

佈景主題圖片呈現是採嵌入固定,不會隨機更新的,在找尋 F2blog 相關資訊時,無意中瀏覽到網友 jerome 的 blog
 (走過的、學過的、看過的  http://jerome.anyday.com.tw/),網站的佈景主題效果隨機更新圖片,正是我想要加入到 "Leonard 幸福快遞" 的元素,在經過求教後 jerome 也不藏私的傾囊相授,在此由衷感謝!

同時參考 flower Design by leison Skin,修改過程還算順利,將修改的語法與大家分享!

最初對於本站佈景主題圖片輪播功能有 2 個想法:

1. 採固定連結對應:點選導行列的首頁‧歸檔‧留言板‧關於我‧連結,即可出現對應的 content backround 圖片。

2. 採隨機式呈現:無論點選導航列 or 文章,只要頁面更新,即可出現隨機的 content backround 圖片。(最後決定採第 2. 方案)

修改的語法如下:

1.random_bg.php 下載至 ./skin/HKSSUCLA/


  1. <?php
  2.  
  3.  $url='./bg';
  4.  
  5.  $files=array();
  6.  if ($handle=opendir("$url")) {
  7.      while(false !== ($file = readdir($handle))) {
  8.            if ($file != "." && $file != "..") {
  9.            if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
  10.            }
  11.      }
  12.  }
  13.  closedir($handle);
  14.  
  15.  $random=rand(0,count($files)-1);
  16.  if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
  17.  elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
  18.  readfile("$url/$files[$random]");
  19.  
  20.  ?>


2.修改 ./skin/HKSSUCLA/layout.css 樣式表中 /*---Main Content--*/(/*---主内容--*/) 找 content_bg.jpg 將 background-image 連結改為 random_bg.php


  1. #mainContent-topimg{
  2.         background-image: url(content_bg.jpg);
  3.         background-repeat: no-repeat;
  4.         background-attachment: scroll;
  5.         background-position: 0 0;
  6.         height: 190px;
  7.         overflow: hidden;
  8. }




  1. #mainContent-topimg{
  2.         background-image: url(random_bg.php);
  3.         background-repeat: no-repeat;
  4.         background-attachment: scroll;
  5.         background-position: 0 0;
  6.         height: 190px;
  7.         overflow: hidden;
  8. }

3.建立 ./skin/HKSSUCLA/bg/ 資料夾,將佈景主題圖片 (bg00.jpg,bg01.jpg,bg02,jpg,bg03,jpg,...) 放入 bg 資料夾內,效果演示如上 #mainContent-topimg 的效果呈現。

引用通告地址: 點擊獲取引用地址
標籤: F2blog 技術交流 Blog 大補帖 佈景圖片 語法
評論: 0 | 引用: 0 | 閱讀: 714 | 列印 | 轉發
 加入書籤
        網路社群

        拜訪我的  MyBlogLog  拜訪我的  Plurk  拜訪我的  twitter  拜訪我的  flickr  拜訪我的  aNobii  拜訪我的  Findbook  拜訪我的  Facebook  拜訪我的  YouTube  拜訪我的  部落格觀察  Yahoo!奇摩拍賣  露天拍賣  eBay

發表評論
暱 稱: 密 碼:
網 址: E - mail:
驗證碼: 驗證碼圖片 選 項:
頭 像:
內 容:
  • 粗體
  • 斜體
  • 底線
  • 插入圖片
  • 超連結
  • 電子郵件
  • 插入引用
  • 表情符號

Leonard Lin. Get yours at bighugelabs.com