日期:2011-10-24  浏览次数:21066 次

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

上面代码要加在header区,不能放在外部CSS文件里。