PHP .NET 西安网站建设 西安做网站 西安网站制作 西安微信开发

西安网站建设

咨询热线:029-81614085
News/建站资讯
Hotline/咨询热线

电话:029-8161 4085
手机:189 9121 9418

网页设计/ Web design
您的位置:首页 > 建站资讯 > 网页设计

用ASP+CSS实现随机背景

浏览次数:767 时间:2011-06-15 09:15:49

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

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( <%= strImageSrcText %>) no-repeat;
     margin: 2em auto;
}

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

copyright©2010-2014 西安久博网络科技有限公司 All Right Reserved 陕ICP备11012006号-1
★久博网络★西安网络公司 | 西安网站建设 | 高端品牌网站建设 | 西安手机网站建设 | 西安APP开发
西安久博网络网站建设

用微信扫一扫