42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
|
// (function($) {
|
||
|
// var cache = [];
|
||
|
// // Arguments are image paths relative to the current page.
|
||
|
// $.preLoadImages = function() {
|
||
|
// var args_len = arguments.length;
|
||
|
// for (var i = args_len; i--;) {
|
||
|
// var cacheImage = document.createElement('img');
|
||
|
// cacheImage.src = arguments[i];
|
||
|
// cache.push(cacheImage);
|
||
|
// }
|
||
|
// }
|
||
|
// })(jQuery)
|
||
|
|
||
|
|
||
|
(function($) {
|
||
|
$.preloadimages = function (arr){
|
||
|
var newimages=[], loadedimages=0
|
||
|
var postaction=function(){}
|
||
|
var arr=(typeof arr!="object")? [arr] : arr
|
||
|
function imageloadpost(){
|
||
|
loadedimages++
|
||
|
if (loadedimages==arr.length){
|
||
|
postaction(newimages) //call postaction and pass in newimages array as parameter
|
||
|
}
|
||
|
}
|
||
|
for (var i=0; i<arr.length; i++){
|
||
|
newimages[i]=new Image()
|
||
|
newimages[i].src=arr[i]
|
||
|
newimages[i].onload=function(){
|
||
|
imageloadpost()
|
||
|
}
|
||
|
newimages[i].onerror=function(){
|
||
|
imageloadpost()
|
||
|
}
|
||
|
}
|
||
|
return { //return blank object with done() method
|
||
|
done:function(f){
|
||
|
postaction=f || postaction //remember user defined callback functions to be called when images load
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
})(jQuery)
|