1
我有一些问题,使用JS预加载图像。我有一个小提琴,我试图创建三个图像对象并逐个加载,但是我只能得到一个图像?任何帮助赞赏。掌握预加载图像
http://jsfiddle.net/gq1oqnxb/1/
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var images = new Array();
images[0] = 'http://hdcomputerwallpaper.com/wp-content/uploads/2013/12/Puppy-images.jpg';
images[1] = 'http://hdcomputerwallpaper.com/wp-content/uploads/2013/12/Puppy-images.jpg';
images[2] = 'http://wallfc.com/wp-content/uploads/2014/09/Little-Birds.jpg';
var i = 0;
while(i < images.length){
var image = new Image(50,50);
image.src = images[i];
image.onload = function(){
$('body').append(image);
i++;
}
i++
}
});
</script>
</head>
<body>
</body>