asp+|css| Random background--When you enter the page, randomly select a picture from the designated picture folder to display as the background. The method described here is implemented with ASP+CSS.
以下是引用片段:
ConstIMGS_DIR="/images"
'设定图片文件夹的地址,随机显示该文件夹内任一张图片
DimobjFSO,objFolderObject,objFileCollection,objFile
DimintFileNumberToUse,intFileLooper
DimobjImageFileToUse
DimstrImageSrcText
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
SetobjFolderObject=objFSO.GetFolder(Server.MapPath(IMGS_DIR))
SetobjFSO=Nothing
SetobjFileCollection=objFolderObject.Files
SetobjFolderObject=Nothing
Randomize()
intFileNumberToUse=Int(objFileCollection.Count*Rnd)+1
intFileLooper=1
ForEachobjFileinobjFileCollection
IfintFileLooper=intFileNumberToUseThen
SetobjImageFileToUse=objFile
ExitFor
EndIf
intFileLooper=intFileLooper+1
Next
SetobjFileCollection=Nothing
strImageSrcText=IMGS_DIR&objImageFileToUse.Name
SetobjImageFileToUse=Nothing
以下是引用片段:
#pic{
width:400px;
height:300px;
background:url()no-repeat;
margin:2emauto;
}
The code above should be added to the header area and not be placed in an external CSS file.