相關資訊
本類常用軟件
-
福建農村信用社手機銀行客戶端下載下載量:584204
-
Windows優化大師下載量:416896
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農村信用社手機銀行客戶端下載下載量:365699
-
快播手機版下載量:325855
這篇文章提供給大家分享學習的是關于用ASP+CSS實現隨機背景的實例代碼,希望能夠給大家帶來幫助或啟發。
隨機背景--當你每次進入該頁面時,從已指定的圖片文件夾中,隨機選取一個圖片作為背景顯示。這里介紹的方法是用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
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;
}
#pic{
width: 400px;
height: 300px;
background: url(<%= strImageSrcText %>) no-repeat;
margin: 2em auto;
}
上面代碼要加在header區,不能放在外部CSS文件里。
熱門評論
最新評論