Using ASP+CSS to realize random background

Source: Internet
Author: User
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.