精品主页 | 软件下载 | 系统下载 | 精品导航| 精彩图片 | 转帖工具 | 版主申请 | 影视下载
发新话题
打印

教你用ASP CSS实现网页随机背景

本主题由 xiaoma 于 2008-4-4 22:45 移动

教你用ASP CSS实现网页随机背景

  


                   随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP CSS来实现的。


  ASP源代码:













  ConstIMGS_DIR="/images[/img]  '设定图片文件夹的地址,随机显示该文件夹内任一张图片

  DimobjFSO,objFolderObject,objFileCollection,objFile

  DimintFileNumberToUse,intFileLooper

  DimobjImageFileToUse

  DimstrImageSrcText

  SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

  SetobjFolderObject=objFSO.GetFolder(Server.MapPath(IMGS_DIR))

  SetobjFSO=Nothing

  SetobjFileCollection=objFolderObject.Files

  SetobjFolderObject=Nothing

  Randomize()

  intFileNumberToUse=Int(objFileCollection.Count*Rnd) 1

  intFileLooper=1

  ForEachobjFileinobjFileCollection

  IfintFileLooper=intFileNumberToUseThen

  SetobjImageFileToUse=objFile

  ExitFor

  EndIf

  intFileLooper=intFileLooper 1

  Next

  SetobjFileCollection=Nothing

  strImageSrcText=IMGS_DIR&objImageFileToUse.Name

  SetobjImageFileToUse=Nothing


  CSS源代码:













  #pic{

  width:400px;

  height:300px;

  background:url()no-repeat;

  margin:2emauto;

  }


  上面代码要加在head区,不能放在外部CSS文件里。

TOP

发新话题