Wednesday, 28 March 2012

Javascript image preload

Welcome to Technology




How to get rid of the delay that happens when you use multiple images with ‘onmouseover’? Preload all the images.


/**
*
*  Image preload
*  http://www.webtoolkit.info/
*
**/
 
function ImagePreload() {
	if (typeof(arguments) != 'undefined') {
		for (i=0; i<arguments.length; i++ ) {
			if (typeof(arguments[i]) == "object") {
				for (k=0; k<arguments[i].length; k++) {
					var oImage = new Image;
					oImage.src = arguments[i][k];
				}
			}
 
			if (typeof(arguments[i]) == "string") {
				var oImage = new Image;
				oImage.src = arguments[i];
			}
		}
	}
}

No comments:

Post a Comment