Random background--Whenever you enter this page, a picture will be randomly selected from the specified picture folder to be displayed as the background. The method introduced here is implemented using ASP+CSS.
Here is a quote: Const IMGS_DIR = "/images" 'Set the address of the picture folder and randomly display 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 Each 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 objImageFileToUse = Nothing |
Here is the reference snippet: #pic{ width: 400px; height: 300px; background: url(<%= strImageSrcText %>) no-repeat; margin: 2em auto; } |
The above code must be added to the header area and cannot be placed in an external CSS file.