WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

用ASP+CSS实现网页随机背景

更新时间:2006-10-24 09:24 作者:佚名点击:
   随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP+CSS来实现的。

  ASP源代码:

以下是引用片段:
  Const IMGS_DIR = "/images"
  '设定图片文件夹的地址,随机显示该文件夹内任一张图片
  Dim objFSO, objFolderObject, objFileCollection, objFile
  Dim intFileNumberToUse, intFileLooper
  Dim objImageFileToUse
  Dim strImageSrcText
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  Set objFolderObject = objFSO.GetFolder(Server.MapPath(IMGS_DIR))
  Set objFSO = Nothing
  Set objFileCollection = objFolderObject.Files
  Set objFolderObject = Nothing
  Randomize()
  intFileNumberToUse = Int(objFileCollection.Count * Rnd) + 1
  intFileLooper = 1
  For Each objFile in objFileCollection
  If intFileLooper = intFileNumberToUse Then
  Set objImageFileToUse = objFile
  Exit For
  End If
  intFileLooper = intFileLooper + 1
  Next
  Set objFileCollection = Nothing
  strImageSrcText = IMGS_DIR & objImageFileToUse.Name
  Set objImageFileToUse = Nothing

  CSS源代码:

以下是引用片段:
  #pic{
  width: 400px;
  height: 300px;
  background: url() no-repeat;
  margin: 2em auto;
  }

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

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容