Using ASP+CSS to realize random background

Source: Internet
Author: User

Random background-When you go to the page, randomly select a picture from the designated picture folder to display as a background. The method described here is implemented with ASP+CSS.

asp--from ASP101

 
 
Const imgs_dir = "/images"
Set the address of the picture folder, which randomly displays the Any picture in the folder
Dim objFSO, Objfolderobject, Objfilecollection, objfile
Dim intfilenumbertouse, Intfilelooper
Dim Objimagefiletouse
Dim strimagesrctext
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Set 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 all 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 Objimage Filetouse = Nothing

Css

 
  
  
The following is a reference fragment:





}

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.