1 var url_prefix = 'http://bluestreeter.adidas.com.cn/assets/images/'; 2 var sources = [ 3 "landing/01_01.jpg", 4 "landing/01_02.jpg", 5 "landing/01_03.jpg", 6 "landing/01_04.jpg", 7 "landing/01_05.jpg", 8 "landing/01_06.jpg", 9 "landing/01_07.jpg", 10 "landing/01_08.jpg", 11 "landing/01_09.jpg", 12 "landing/01_10.jpg", 13 "landing/01_11.jpg", 14 "landing/01_12.jpg", 15 "landing/01_13.jpg", 16 "landing/01_14.jpg", 17 "landing/01_15.jpg", 18 "landing/02_01.jpg", 19 "landing/02_02.jpg", 20 "landing/02_03.jpg", 21 "landing/02_04.jpg", 22 "landing/02_05.jpg", 23 "landing/02_06.jpg", 24 "landing/02_07.jpg", 25 "landing/02_08.jpg", 26 "landing/02_09.jpg", 27 "landing/02_10.jpg", 28 "landing/02_11.jpg", 29 "landing/02_12.jpg", 30 "landing/02_13.jpg", 31 "landing/02_14.jpg", 32 "landing/02_15.jpg", 33 "landing/03_01.jpg", 34 "landing/03_02.jpg", 35 "landing/03_03.jpg", 36 "landing/03_04.jpg", 37 "landing/03_05.jpg", 38 "landing/03_06.jpg", 39 "landing/03_07.jpg", 40 "landing/03_08.jpg", 41 "landing/03_09.jpg", 42 "landing/03_10.jpg", 43 "landing/03_11.jpg", 44 "landing/03_12.jpg", 45 "landing/03_13.jpg", 46 "landing/03_14.jpg", 47 "landing/03_15.jpg" 48 ]; 49 50 51 loadImages(sources.map(function (currentValue) { 52 return url_prefix + currentValue 53 }), function () { 54 alert('加载完毕') 55 }); 56 57 function loadImages(sources, callback) { 58 var loadedImages = 0; 59 var numImages = 0; 60 var images = []; 61 numImages = sources.length; 62 for (var i = 0, len = sources.length; i < len; i++) { 63 images[i] = new Image(); 64 images[i].onload = function () { 65 if (++loadedImages >= numImages) { 66 callback(images); 67 } 68 69 }; 70 images[i].src = sources[i]; 71 } 72 }
先绑定Image onload事件,然后再给src赋值。这样load事件会正常触发。