通过判断Image加载完了再改变img的src值,在未加载前,可以先给和load图片。
var oImg = document.getElementById('oImg');
var img = new Image();
img.src = '1.jpg';
img.onload = function() {
oImg.src = this.src;
oImg.style.width=this.width;
oImg.style.height=this.height;
}
<img src="load.gif" id="img01" alt="img" />
实现Load效果,具体实例:
/examples/js-load-img/loadimg.html








