Html Command To Load An Image First

Discussion in 'HTML & Website Design' started by androide, Sep 15, 2009.

  1. #1
    Hello,

    I have a website with more images on its index page. Is there the possibility to load first the images contained in the header and just after the following ?

    When I refresh my website I always see that the firsts images to load are the ones down in the page.. :-(

    Thank you
     
    androide, Sep 15, 2009 IP
  2. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This can be done only with JavaScript, but I don't recommended to do that.
    All image that you want to display later must be dynamically added with script.

    
    <head>
        <script type='text/javascript'>
            var images = new Array (["imageURL", "image_1"], ["imageURL", "image_2"], ["imageURL", "image_3"]);
            function LoadMyImages () {
                for (var i=0; i < images.length; i++) {
                    var img = document.getElementById (images[i][1]);
                    if (img) {
                        img.src = images[i][0]
                    }
                }
            }
        </script>
    </head>
    <body  onload="LoadMyImages">
        <img id="image_1" />
        <img id="image_2" />
        <img id="image_3" />
    </body>
    
    Code (markup):
    getElementById,
    Array object
     
    gumape, Sep 15, 2009 IP
  3. androide

    androide Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Great!

    I was able to make it working.

    Thank you very much.
     
    androide, Sep 16, 2009 IP