The following example demonstrates the preloading of images:
<TITLE>Example- preloading of images</TITLE>
heavyImage = new Image();
heavyImage.src = "image.jpg";
<img name="img01" src="image.jpg"></a>
Note that the image tag does not itself handle onMouseOver() and onMouseOut() events. Hence <img> tag in the example above has been enclosed in an <a> tag, which does include support for those event types.
- Save the file as preloading.html in your system.
- Just open the file in the browser, you will notice how the image gets loaded fast.