這裏是一個通用的一個(作品與任意數量的圖像)
function preload(images, callback){
var imageElements = [],
counter = images.length,
lfunc = function(){if (--counter === 0 && callback) callback(imageElements);};
// first create the images and apply the onload method
for (var i = 0, len = images.length; i < len; i++){
var img = new Image();
imageElements.push(img);
img.onload = lfunc;
img.src = images[i];
}
}
function codeOncePreloadCompletes(preloadedImages){
// Do whatever you want here
// images are preloaded
// you have access to the preloaded image if you need them
// with the preloadedImages argument
}
// USAGE
preload(['b.png', 'c.png'], codeOncePreloadCompletes);
// OR
preload(['b.png', 'c.png'], function(preloadImages){
// write directly here what to do after preload
});
今天晚上我正在學習我的課:基於複製/粘貼的速度回答在iPad上通常不會成功。 – JKing 2012-04-11 10:46:42