can u help me with my preloader code?

Discussion in 'Javascript' started by white lightning, Sep 29, 2007.

  1. Below is a simple preloader code I have... What I want to do is once
    the images have completed preloading, the "Loading Images..." text
    must disappear. I am not able to do it.

    <html>
    <head>
    <title>Preloader</title>
    </head>

    <body>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
    nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
    volutpat.</p>

    <div align="center">
    <script type="text/javascript">
    var imagenames=new Array('http://tbn0.google.com/images?
    q=tbn:_Mg6ZYPbkBTWYM:http://www.sat.dundee.ac.uk/jpg/20020131-1205-
    large.jpg' , 'http://tbn0.google.com/images?
    q=tbn:UhAhRmP9ngqNoM:http://www.ari.uni-heidelberg.de/gaia/gallery/GR/
    gr0283-01.artistic-Gaia-Galaxy-large.jpg');

    var imagesdone=false;
    var loaded=0, preloader, images=new Array();
    var txt ='<p id="preloader" style="position:relative; background-
    color:#aa00dd; color:#fff; font-size:12px; line-height:25px; vertical-
    align:middle; width:300px; text-align:center; font-
    family:Arial;">Loading Images...</p>';
    document.write(txt);

    function loadimages(){
    preloader=document.getElementById('preloader');
    for(n=0; n < imagenames.length; n++){
    images[n]=new Image();
    images[n].src=imagenames[n];
    setTimeout("checkload('+n+')" ,n*100);
    }
    }

    function dispbars(){
    loaded++;
    if(loaded >= imagenames.length) setTimeout('hidepreloader()',
    800);
    }

    function checkload(index){
    (images[index].complete)? dispbars() :
    setTimeout('checkload('+index+')', 100);
    }

    function hidepreloader(){
    preloader.style.visibility="hidden";
    imagesdone=true;
    }
    loadimages();
    </script>
    </div>

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
    nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
    volutpat.</p>

    </body>
    </html>
    white lightning, Sep 29, 2007
    #1
    1. Advertising

  2. On Sep 29, 1:58 pm, Randy Webb <> wrote:
    > white lightning said the following on 9/28/2007 11:47 PM:
    >
    > > Below is a simple preloader code I have... What I want to do is once
    > > the images have completed preloading, the "Loading Images..." text
    > > must disappear. I am not able to do it.

    >
    > You obviously are not able to read, understand, and appreciate the
    > advice already given to you about this question. What is to make anyone
    > believe your attitude will change now if someone spends the time to
    > explain everything that is wrong with your code, how to fix it, and then
    > have you post the same question again tomorrow?
    >


    If you find my question irritating, you do not have to reply... I can
    ask whatever I want to ask.
    white lightning, Sep 29, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jj
    Replies:
    3
    Views:
    1,228
    bruce barker
    Jan 20, 2009
  2. FluxForums

    Image Preloader

    FluxForums, Feb 22, 2004, in forum: Javascript
    Replies:
    3
    Views:
    102
    Hywel
    Feb 22, 2004
  3. David

    Stop do while loop - image preloader

    David, Aug 10, 2005, in forum: Javascript
    Replies:
    4
    Views:
    163
    David
    Aug 10, 2005
  4. Image Preloader

    , Dec 4, 2005, in forum: Javascript
    Replies:
    2
    Views:
    95
  5. Ross

    preloader not working

    Ross, Jan 5, 2006, in forum: Javascript
    Replies:
    8
    Views:
    100
    Thomas 'PointedEars' Lahn
    Jan 5, 2006
Loading...

Share This Page