国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用ASP+CSS實現隨機背景

2019-11-18 17:11:32
字體:
來源:轉載
供稿:網友

隨機背景--當你每次進入該頁面時,從已指定的圖片文件夾中,隨機選取一個圖片作為背景顯示。這里介紹的方法是用asp+CSS來實現的。

ASP--來自ASP101

以下是引用片段:
Const IMGS_DIR = "/images" 
 '設定圖片文件夾的地址,隨機顯示該文件夾內任一張圖片
Dim objfso, objFolderObject, objFileCollection, objFile
Dim intFileNumberToUse, intFileLooper
Dim objImageFileToUse
Dim strImageSrcText
Set objFSO = Server.CreateObject("ScrSet 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文件里。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 友谊县| 通榆县| 黄陵县| 福贡县| 江永县| 德安县| 伽师县| 滨州市| 右玉县| 鱼台县| 册亨县| 清原| 宽甸| 富裕县| 九台市| 宁德市| 金华市| 涿鹿县| 大理市| 开平市| 洞头县| 炉霍县| 盐城市| 原阳县| 名山县| 安岳县| 贵州省| 永福县| 汉中市| 凤庆县| 德庆县| 樟树市| 东明县| 德安县| 普定县| 大宁县| 舒兰市| 九江市| 济南市| 通州市| 新蔡县|