商讯信箱
用户名: @
密  码:   注册|忘记密码
登录
个人用户经销商
信箱 E杂志
您的位置:首页 > 学院 > 正文       

用ASP+CSS实现随机背景

作者:网络 fifty studio  2006-06-06   

    【IT168 实用技巧】随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP+CSS来实现的。(相关文章:避免表格被撑开变形的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(<%= strImageSrcText %>) no-repeat;
    margin: 2em auto;
}

 中关于“编程开发其它”的问题及解答>>>

1
有问必答
【内容导航】
第1页:用ASP+CSS实现随机背景
©版权所有。未经许可,不得转载。
[责任编辑:李乾仑] [我要挑错]
相关产品
本文相关产品
   没有相关产品