Preloading Images?

Discussion in 'JavaScript' started by gobbly2100, Dec 19, 2007.

  1. #1
    Hey,

    I am just playing around with the "onMouseOver" event handler using it to swap images and such but I just wondered what the syntax is to preload the images to get rid of the delay on hover?

    I know I put it in the head but I am having a blank moment and I don't know how I create it in the head and then how do I referene to it for the source?

    I hope that is clear enough to understand.

    Thanks!
     
    gobbly2100, Dec 19, 2007 IP
  2. thinlight

    thinlight Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var img = new Image();
    img.src = 'http://your.tld/logo.gif';
    Code (markup):
    This piece of code will load logo.gif.
    Try it.
     
    thinlight, Dec 20, 2007 IP
  3. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Just an addition to that.

    For multiple images, you can create an array of "Image()" objects and then set each ones src.
     
    arnek, Dec 20, 2007 IP