This ASP Script recurses through a directory tree and loads images into a DHTML preloader.
First off, big thanks to Brian from Script Asylum for letting me use his DHTML site preloader. This
version will be even less work, because all you do is tell the ASP to drill down through a directory
structure looking for images, and it will place all the image names into an array, and off it goes.
The setup for this is incredibly simple. First off, open Preloader.ASP, and change the following variables:
- boolRecurse: Tell the script to drill down through subdirectories within the folder you choose
(True/False)
- strVirtualRoot: The folder that contains all the images
<%
boolRecurse = True ' Recurse through subdirectories? True/False
strVirtualRoot = "../../Images" ' Directory
strRootFolder = Server.MapPath(strVirtualRoot) ' Grab the directory
intSize = 0
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strRootFolder)
strOutput = TraverseFolder(objFolder, strVirtualRoot, boolRecurse)
strOutput = mid(strOutput, 1, Len(strOutput)-2)
Set objFSO = Nothing
Set objFolder = Nothing
Function TraverseFolder(objFolder, strVirtualRoot, boolRecurse)
strOutput = ""
arrImages = Array("gif", "jpg", "png", "jpeg")
'Only process directories that do NOT start with
'an underscore.
If Not Left(objFolder.Name, 1) = "_" then
Dim objFile, strPath, strFileName, strFileSize, strExtension
'Iterate through each file in the folder
For Each objFile in objFolder.Files
' Obtain the extension of the current file
strPath = objFile.Path
strFileName = objFile.Name
intFileSize = objFile.Size
strExtension = Ucase(Right(strPath, Len(strPath) - InStrRev(strPath, ".")))
' See if file is an image
For x = LBound(arrImages) to UBound(arrImages)
If strExtension = Ucase(arrImages(x)) then
strOutput = strOutput & "'" & strVirtualRoot & "/" & strFileName & "', "
intSize = intSize + intFileSize
End If
Next
Next
If boolRecurse then
'Recurse through the folder's subdirectories
For Each objSubFolder in objFolder.SubFolders
strOutput = strOutput & TraverseFolder(objSubFolder, strVirtualRoot & "/" &
objSubFolder.Name, boolRecurse)
Next
End If
TraverseFolder = strOutput
End If
End Function
%>
Second step is to change the look and feel variables of the site preloader, in Progressbar.ASP.
Also be sure to change the action variable, this is a function which will perform an action when all the
images are loaded, e.g. go to another page, pop up an alert, etc.
<!--#include file="preloader.ASP"-->
// Progressbar - Version 2.5
// Author: Brian Gosselin of http://scriptasylum.com
// PUT THE NAMES OF ALL YOUR IMAGES THAT NEED TO BE "CACHED" IN THE "imagenames" ARRAY.
// DONT FORGET THE COMMA BETWEEN EACH ENTRY, OR THE TICK MARKS AROUND EACH NAME.
// WHEN ALL THE IMAGES ARE DONE LOADING, THE "imagesdone" VARIABLE IS SET TO "TRUE"
var imagenames=[<%=strOutput%>];
var yposition = 50; // POSITION OF LOAD BAR FROM TOP OF WINDOW, IN PIXELS
var loadedcolor = '#AAAAAA' ; // PROGRESS BAR COLOR
var unloadedcolor = 'lightgrey'; // BGCOLOR OF UNLOADED AREA
var barheight = 20; // HEIGHT OF PROGRESS BAR IN PIXELS (MIN 20)
var barwidth = 400; // WIDTH OF THE BAR IN PIXELS
var bordercolor = 'black'; // COLOR OF THE BORDER
var intSize = '<%=FormatNumber(intSize/1024, 0)%>'; // SIZE IN BYTES OF ALL THE IMAGES
// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE IMAGES ARE DONE LOADING.
// IF NO ACTION IS DESIRED, TAKE EVERYTHING OUT FROM BETWEEN THE CURLY BRACES ({})
// BUT LEAVE THE FUNCTION NAME AND CURLY BRACES IN PLACE.
// PRESENTLY, IT IS SET TO DO NOTHING, BUT CAN BE CHANGED EASILY.
// TO CAUSE A REDIRECT, INSERT THE FOLLOWING LINE IN IT:
document.location.href="http://redirect_page.HTML";
// Update: setCookie() used to "remember" that people have loaded the page, and bypass preloading.
var action=function()
{
setCookie();
}
Click here to test this script (Preload.HTML)
Download source (PreLoad.zip)
External Links
http://scriptasylum.comURL:http://www.qqread.com/asp/2006/10/n222533.html进入讨论组讨论。
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- asp+ajax打造无刷新新闻评论系统 (846次浏览)
- 绝对免费顶级域名+免费500MB ASP?? (728次浏览)
- ASP后门之终极伪装 (601次浏览)
- FTP的安全问题 《转》 (589次浏览)
- 如何正确显示数据库中的图片 (503次浏览)
- 用户登录/注册程序——Flash+ASP (492次浏览)
- SQL注入漏洞全接触 (381次浏览)
- asp+sqlserver 分页方法(不用存储过程) (314次浏览)
- Windows操作系统出现死机故障的解决方法 (202次浏览)
- 对ASP 动态包含文件方法的改进 (152次浏览)



