您现在的位置: 网页制作教程网 >> 网络编程 >> Asp教程 >> ASP实例教程 >> 文章正文

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

作者:forestga…

来源:forest53.com

热度:

2006-10-23 10:26:53

随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用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文件里。

我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。
网站简介 | 联系方式 | 意见建议 | 版权说明
Copyright © 2007 All rights reserved
滇ICP备06006992号