snippets

Предзагрузка изображений js [snippets]

2 рабочие функции для пред загрузки картинок, нативная и jQuery.

	

function preload(images) {
   if (typeof document.body == "undefined") return;
 	    try {

 	        var div = document.createElement("div");
 	        var s = div.style;
 	            s.position = "absolute";
 	        s.top = s.left = 0;
 	        s.visibility = "hidden";
 	        document.body.appendChild(div);
         div.innerHTML = "";
 	        var lastImg = div.lastChild;
 	        lastImg.onload = function() { document.body.removeChild(document.body.lastChild); };
 	     }
 	     catch(e) {
 	        // Error. Do nothing.
     }
 	}
 	});

	jQuery.preloadImages = function () {
	    var images = (typeof arguments[0] == 'object') ? arguments[0] : arguments;
	    for (var i = 0; i < images.length; i++) {
	        jQuery("").attr("src", images[i]);
	    }
	}

Найдено на просторах.
http://clip2net.com/clip/m11386/1304961837-clip-11kb.png