知识库

新手技巧:用ASP+CSS实现随机背景

来源: 本站    类别: 知识库    日期: 2013/5/2

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


相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com