This post teaches you the proper efficient way to preload images with javascript.
if (document.images)
{
preload_image = new Image();
img_path = new Array();img_path[0] = "http://kilroylives.com/images/buttons/avatar.gif";
img_path[1] = "http://kilroylives.com/images/buttons/avatar-over.gif";
img_path[2] = "http://kilroylives.com/images/buttons/enlarge.gif";
img_path[3] = "http://kilroylives.com/images/buttons/enlarge-over.gif";
img_path[4] = "http://kilroylives.com/images/buttons/favorite.gif";for(var i = 0; i<=img_path.length; i++)
preload_image.src = img_path[i];
}
All you need to do is add more img_path[x] = ""; line for each image to preload. This is very usual when using CSS text links with background images.
2 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE's Hottest Posts
Learn to Swap your ALT and CTRL keys in Windows XP. Windows has something called Scancode keys built in (but not really); this will let you switch the positioning of your alt and ctrl key to act like an apple layout. The jump from Apple Command to CTRL is messing with my pinky so lets fix it. Read Full Article...
Read Full Article...
Read Full Article...
[...] doing this it is a good idea to preload your images with javascript to avoid the get lag that occurs when mouses over the link for the first [...]
[...] way to do this is with javascript, the other way is with [...]
Leave a Comment