用ASP+CSS實(shí)現(xiàn)網(wǎng)頁(yè)隨機(jī)背景
來(lái)源:易賢網(wǎng) 閱讀:1943 次 日期:2015-04-16 11:32:32
溫馨提示:易賢網(wǎng)小編為您整理了“用ASP+CSS實(shí)現(xiàn)網(wǎng)頁(yè)隨機(jī)背景”,方便廣大網(wǎng)友查閱!

隨機(jī)背景--當(dāng)你每次進(jìn)入該頁(yè)面時(shí),從已指定的圖片文件夾中,隨機(jī)選取一個(gè)圖片作為背景顯示。這里介紹的方法是用ASP+CSS來(lái)實(shí)現(xiàn)的。

ASP--來(lái)自ASP101

以下是引用片段:

Const IMGS_DIR = "/images"

'設(shè)定圖片文件夾的地址,隨機(jī)顯示該文件夾內(nèi)任一張圖片

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區(qū),不能放在外部CSS文件里

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看技術(shù)文章
易賢網(wǎng)手機(jī)網(wǎng)站地址:用ASP+CSS實(shí)現(xiàn)網(wǎng)頁(yè)隨機(jī)背景
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)