加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

运用ASP+CSS实现随机背景

发布时间:2023-04-30 13:22:38 所属栏目:Asp教程 来源:
导读:本文介绍了ASP程序生成随机背景的方法,即,当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP+CSS来实现的。

ASP

以下是引用片段:

Const IMGS_DIR
本文介绍了ASP程序生成随机背景的方法,即,当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用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;
 
}上面代码要加在header区,不能放在外部CSS文件里。
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章