Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Las Vegas
    Posts
    231
    Member #
    1169
    Would anyone happen to have a image preloading script? I could really use one for my mouse overs

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    This goes in the head section:

    First you create a new image object:
    Code:
    var new_image=new Image();
    This object contains no info so far as to width/height JPEG/GIF.
    next you write:
    Code:
    new_image.src="rolloverState.gif";
    This forces the browser to download the image into its cache by setting its object's src. Now it should swap without any delay.

    Sample code:
    Code:
    <html><head><title>Preload</title>
    <script language="JavaScript">
    <!--
    var over_image=new Image();
    over_image.src="rollover.gif";
    -->
    </script>
    </head>
    
    <body>
    <a href="#"
      onMouseOver="window.document.test.src='rollover.gif';"
      onMouseOut="window.document.test.src='static.gif';"
      onClick="return false";>
    <img src="static.gif" name="test" border="0">
    </a>
    </body>
    </html>
    You BTW don't have to put the object info in the <head> section, however it keeps your <body> section cleaner.
    Also if you want to put multiple images into cache, you just repeat the head section, but give a different object name to each "new Image()" object. (like rollover1, rollover2, rollover3 etc...)
    S. Rosland


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:56 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com