欢迎光临
我们一直在努力

ASP/DHTML Image Preloader

建站超值云服务器,限时71元/月

tutorials & code snips: graphics & charts: images\\

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 folders 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.com

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP/DHTML Image Preloader
分享到: 更多 (0)