whadiz.com: What is?
Search Articles:     Home | About | Tools | Contact Us
Games
Board Games
Online Games
Databases
Sql Server
Programming
Visual C# in ASP.Net
JavaScript
Humor
Satire
Web Design
Html

Clever Facts Section

What is JavaScript preload images? | JavaScript preload images | JavaScript remove waiting for images to load during mouseover

What is JavaScript preload images?

JavaScript preload images are loading an image into the cache of the browser, even before the image is needed. JavaScript preload images come in handy when creating mouseover effects with images. When doing the mouseover, the image should be immediately available. JavaScript preload images remove any delay in waiting for images to load when doing a mouseover with images. 

What is the code to JavaScript preload images?

The following code is handy for JavaScript preloading a single image:

<SCRIPT language="JavaScript">
    picture=new Image;
    picture.src="http://whadiz.com/images/logo1.gif";
</SCRIPT>

You first need to define an image and then the source of the image. You can also define explicit width and height attributes for the image, for example:

picture=new Image(100,25);

Does all browsers support JavaScript preload images?

JavaScript preload images is dependant on the browser's ability to create and manipulate an Image object.

To make sure a browser has this ability, you may wish to add a test as follows:

<SCRIPT language="JavaScript">
if (document.images) {
    picture=new Image;
    picture.src="http://whadiz.com/images/logo1.gif";
}
</SCRIPT>

Where should I place the JavaScript preload images code?

The ideal place to put the JavaScript preload images code would be in the HEAD section of your HTML.

Link to this article:

Browse some more: Next Article | Next Fact | More JavaScript Articles | More Clever Facts


Copyright © 2021 whadiz.com. All rights reserved.
whadiz.com: What is JavaScript preload images? | JavaScript preload images | JavaScript remove waiting for images to load during mouseover
Home of the answer "what is"