Results 1 to 3 of 3

Thread: Preload Image (with progress bar) Script II Help

  1. #1
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    1) Script Title: Preload Image (with progress bar) Script II Code

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...loadimage2.htm

    3) Describe problem:

    Hello all,

    I use this web site often and it has been very very helpful. I am using the Preload Image (with progress bar) Script II Code

    I am building a site that is purely based on images. The image loader is awesome, but I am having one problem. The image loader is on the main/home page. So it works great the first time you access the site, then when you click to another page it works great, but the problem happens when you click the back button to go back or just go back to the main page, it re-loads the images again or every time you go back to the main page.

    Is there any way to only have the image loader load the images on the first time that page is accessed or something along those lines?

    Thank you for your help in advance.
    Last edited by jscheuer1; 08-05-2010 at 04:37 PM. Reason: duplicates after thread merge

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    // Progressbar - Version 2.0
    // Author: Brian Gosselin of http://scriptasylum.com
    // Featured on Dynamic Drive (http://www.dynamicdrive.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=new Array( 'http://www.vicsjavascripts.org.uk/StdImages/One.gif');
    
    var yposition=250;                                  //POSITION OF LOAD BAR FROM TOP OF WINDOW, IN PIXELS
    var loadedcolor='gray' ;                // PROGRESS BAR COLOR
    var unloadedcolor='white';                   // BGCOLOR OF UNLOADED AREA
    var barheight=15;                                 // HEIGHT OF PROGRESS BAR IN PIXELS (MIN 25)
    var barwidth=350;                                // WIDTH OF THE BAR IN PIXELS
    var bordercolor='black';                       // COLOR OF THE BORDER
    
    //DO NOT EDIT BEYOND THIS POINT
    var NS4 = (navigator.appName.indexOf("Netscape")>=0 && parseFloat(navigator.appVersion) >= 4 && parseFloat(navigator.appVersion) < 5)? true : false;
    var IE4 = (document.all)? true : false;
    var NS6 = (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape")>=0 )? true: false;
    var imagesdone=false;
    var blocksize=barwidth/(imagenames.length);
    barheight=Math.max(barheight,25);
    var loaded=0, perouter, perdone, images=new Array();
    var txt=(NS4)?'<layer name="perouter" bgcolor="'+bordercolor+'" visibility="hide">' : '<div id="perouter" style="position:absolute; visibility:hidden; background-color:'+bordercolor+'">';
    txt+='<table cellpadding="0" cellspacing="1" border="0"><tr><td width="'+barwidth+'" height="'+barheight+'" valign="center">';
    if(NS4)txt+='<ilayer width="100%" height="100%"><layer width="100%" height="100%" bgcolor="'+unloadedcolor+'" top="0" left="0">';
    txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+unloadedcolor+'"><center><font color="'+loadedcolor+'" size="1" face="sans-serif">Loading Images...</font></center></td></tr></table>';
    if(NS4) txt+='</layer>';
    txt+=(NS4)? '<layer name="perdone" width="100%" height="'+barheight+'" bgcolor="'+loadedcolor+'" top="0" left="0">' : '<div id="perdone" style="position:absolute; top:1px; left:1px; width:'+barwidth+'px; height:'+barheight+'px; background-color:'+loadedcolor+'; z-index:100">';
    txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+loadedcolor+'"><center><font color="'+unloadedcolor+'" size="1" face="sans-serif">Loading Images...</font></center></td></tr></table>';
    txt+=(NS4)? '</layer></ilayer>' : '</div>';
    txt+='</td></tr></table>';
    txt+=(NS4)?'</layer>' : '</div>';
    document.write(txt);
    function loadimages(){
    if(NS4){
    perouter=document.perouter;
    perdone=document.perouter.document.layers[0].document.perdone;
    }
    if(NS6){
    perouter=document.getElementById('perouter');
    perdone=document.getElementById('perdone');
    }
    if(IE4){
    perouter=document.all.perouter;
    perdone=document.all.perdone;
    }
    cliplayer(perdone,0,0,barheight,0);
    window.onresize=setouterpos;
    setouterpos();
    for(n=0;n<imagenames.length;n++){
    images[n]=new Image();
    images[n].src=imagenames[n];
    setTimeout('checkload('+n+')' ,n*100);
    }}
    function setouterpos(){
    var ww=(IE4)? document.body.clientWidth : window.innerWidth;
    var x=(ww-barwidth)/2;
    if(NS4){
    perouter.moveTo(x,yposition);
    perouter.visibility="show";
    }
    if(IE4||NS6){
    perouter.style.left=x+'px';
     perouter.style.visibility="visible";
    perouter.style.top=yposition+'px';
    }}
    function dispbars(){
    loaded++;
    cliplayer(perdone, 0, blocksize*loaded, barheight, 0);
    if(loaded>=imagenames.length){
     hideperouter();
    }
    else {
    }
    
    
    }
    function checkload(index){
    (images[index].complete)? dispbars() : setTimeout('checkload('+index+')', 100);
    }
    function hideperouter(){
    (NS4)? perouter.visibility="hide" : perouter.style.visibility="hidden";
    imagesdone=true;
    }
    function cliplayer(layer, ct, cr, cb, cl){
    if(NS4){
    layer.clip.left=cl;
    layer.clip.top=ct;
    layer.clip.right=cr;
    layer.clip.bottom=cb;
    }
    if(IE4||NS6)layer.style.clip='rect('+ct+' '+cr+' '+cb+' '+cl+')';
    }
    window.onload=loadimages;/*]]>*/
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Vic,

    Thank you very much for your help, and I am sorry about the duplicate post. I tried using the new code that you attached, and it is still doing the same thing. Is there any way you can show me exactly where the code changes or what I am doing wrong?

    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •