Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2006, 10:34 PM   PM User | #1
ikilledsanta
New Coder

 
Join Date: May 2005
Posts: 78
Thanks: 3
Thanked 0 Times in 0 Posts
ikilledsanta is an unknown quantity at this point
Easy preload image

Ok, I'm sure this will only take half a second. I remember seeing this somewhere. What I want is to load "pictures/navbarbg2.jpg" in javascript. I have a image swap on a picture, and when I hover over one picture, there is a blink where the image is loading. If I have javascript put the hover image on cache, I think that will remove the blink.
ikilledsanta is offline   Reply With Quote
Old 12-28-2006, 12:05 AM   PM User | #2
joh6nn
wei wu wei


 
joh6nn's Avatar
 
Join Date: Jun 2002
Location: 72° W. 48' 57" , 41° N. 32' 04"
Posts: 1,887
Thanks: 0
Thanked 1 Time in 1 Post
joh6nn is an unknown quantity at this point
there're about a million scripts for this, but here's mine:

Code:
function preLoad(args){
	if (document.images){
		var img = new Image();
		var failed = [];
		img.onerror = function(){
			failed[failed.length] = this.src;
			if(args.length > 0){ this.src = args.shift(); }
		}
		img.onload = function(){
			if(args.length > 0){ this.src = args.shift(); }
		}
		img.src = args.shift();
	}
	else { var failed = args; }
	return failed;
}
use it like this:
Code:
preLoad(["pictures/navbarbg2.jpg"]);
preLoad(["preloading.jpg", "multiple.png", "files.gif"]);
__________________
bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

i am a loser geek, crazy with an evil streak,
yes i do believe there is a violent thing inside of me.
joh6nn is offline   Reply With Quote
Old 12-28-2006, 06:40 AM   PM User | #3
ikilledsanta
New Coder

 
Join Date: May 2005
Posts: 78
Thanks: 3
Thanked 0 Times in 0 Posts
ikilledsanta is an unknown quantity at this point
Well, it seemed to work (always hard to tell). Thanks a lot.
ikilledsanta is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:09 AM.


Advertisement
Log in to turn off these ads.