手机
当前位置:查字典教程网 >编程开发 >ASP教程 >用ASP+CSS实现随机背景
用ASP+CSS实现随机背景
摘要:随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP+CSS来实现的。ASP--...

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

【用ASP+CSS实现随机背景】相关文章:

用ASP进行网络打印的功能

ASP实现URL编码

用ASP实现对MP3曲目信息的操作

ASP利用Google实现在线翻译功能

ASP中一个用VBScript写的随机数类

用ASP木马实现FTP和解压缩

如何用ASP代码实现虚拟主机

用ASP+FSO生成JS文件

用ASP+XML打造留言本

用ASP实现hashMap功能的类

精品推荐
分类导航