要先获取到图片,才能执行后续操作时,对图片进行预处理
//图片预加载
function preloadImages(arr, callback) {
$('#loading',window.parent.document).show()
var arr = typeof arr != "object" ? [arr] : arr;
var aImages = [],
iLoadedImages = 0,
iLoadCount = arr.length;
for (var i = 0; i < arr.length; i++) {
aImages[i] = new Image();
aImages[i].src = arr[i];
if (aImages[i].complete) {
iLoadCount--;
if (iLoadCount === 0) {
typeof(callback) === 'function' && callback();
break;
}
continue;
}
aImages[i].onload = aImages[i].error = function() {
iLoadedImages++;
iLoadedImages === iLoadCount && typeof(callback) === 'function' && callback();
}
}
}