All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
用ASP+CSS实现网页随机背景_[Html教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/3/30 5:35:35 Browse times: 368 Comment times: 0

用ASP+CSS实现网页随机背景_[Html教程]


Head photo

Go homepage
Upload pictures
Write articles

用ASP+CSS实现网页随机背景_[Html教程]

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

  #pic{
  width: 400px;
  height: 300px;
  background: url() no-repeat;
  margin: 2em auto;
  }

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

  CSS源代码:
         




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.