用ASP+CSS实现随机背景

作者:  日期:2006-9-21 11:22:18  来源:fifty  点击:次  评论

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

ASP--来自ASP101

以下是引用片段:
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文件里。

〖责任编辑:祁连山〗 发送给好友 打印 顶部
会员名称:
密码:匿名 ·注册·忘记密码?
评论内容:
(最多300个字符)
  查看评论

推荐教程

热点教程

请尊重别人的劳动,原创教程转载必须注明作者及出处
中国教程网简介 | 业务合作 | 广告服务 | 联系我们 | 招聘信息 | English | 网站地图 | 客服中心

中国教程网
©2005-2007