SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Preloading Images

    Hi,

    I really need some help on how to preload images in the browser before they are supposed to appear... Is it difficult?

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that you can just assign a value to a DOM element without actually displaying it which loads the image into the browser cache.

    i.e. document.image[0].src="myfirstimage.gif"

    I'll check on that though.
    It wouldn't be the first time I'd sounded an authority on something I have no idea of


    Andy

  3. #3
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanx, I've never used that DOM-thing... So if you find out anymore, it would be very happy if you explained in a simple way. (I'm no guru on these things either, far from it )

    But thanks-a-million for any help you can give!!

  4. #4
    Sexiest Man Alive Parms18's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    image1 = new Image();
    image1.src = "images/homeover.jpg";
    image2 = new Image();
    image2.src = "images/designover.jpg";
    image3 = new Image();
    image3.src = "images/searchover.jpg";
    image4 = new Image();
    image4.src = "images/toolsover.jpg";

    Rinse and repeat.
    Parms18

  5. #5
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I didn't come back to you on this. I could have sworn that I typed the response, but it's not in the thread so presumably I didn't.

    I was going to point you to this page but hopefully you have the answer now from other responses.


    Andy
    From the English nation to a US location.

  6. #6
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx.

    I'm from Norway, and not at all into the jargon here... What did he mean by "rinse and repeat"?

    Feeling a little confused and embarassed, but better to ask once too many isn't it?

  7. #7
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, repeat these two lines of code as often as you need to. In each case, swap the name of the graphic to be the graphich you are using.


    Andy
    From the English nation to a US location.

  8. #8
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanx!

    That was what I thought. I just didn't dare to assume it without being certain

    Andy

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could use a function to reduce redundant code...

    function newImage(src){
    img = new Image();img.src = src;
    return img;
    }

    img1_off = newImage("img1_off.gif");
    img1_on = newImage("img1_on.gif");

    img2_off = newImage("img2_off.gif");
    img2_on = newImage("img2_on.gif");

    img3_off = newImage("img3_off.gif");
    img3_on = newImage("img3_on.gif");

    ect...
    travis


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
  •