Script requared

Discussion in 'HTML & Website Design' started by igordr, Aug 6, 2009.

  1. #1
    Hi !
    I need javascript which will load all images on the page, before page loads... To eliminate effect when images load slowly, one by one... Thanks !
     
    igordr, Aug 6, 2009 IP
  2. optimeramera

    optimeramera Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Google is your friend. ;) By googling "javascript preload images" I found this on the first hit:

    <SCRIPT language="JavaScript">
    <!--
    if (document.images)
    {
      pic1= new Image(100,25); 
      pic1.src="http://someplace.com/image1.gif"; 
    
      pic2= new Image(240,55); 
      pic2.src="http://someplace.com/image2.gif"; 
    
      pic3= new Image(88,31); 
      pic3.src="http://someplace.com/image3.gif"; 
    }
    //-->
    </SCRIPT>
    
    Code (markup):
    This is probably only useful if you have hidden images which are displayed on mouseovers and things like that. You could probably automate it in a for-loop if you've named all your images sequentially, like image01.jpg, image02.jpg etc. Otherwise it might be trickier.
     
    optimeramera, Aug 6, 2009 IP
  3. 1 FineLine

    1 FineLine Peon

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Make sure you've also optimized your images to reduce file size. That will reduce load times as well
     
    1 FineLine, Aug 6, 2009 IP