首页 > 代码库 > js判断图片加载完成

js判断图片加载完成

<!DOCTYPE><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><img id="mainPic" src="http://img1c.xgo-img.com.cn/pics/1843/b1842753.jpg" /><script>loadingImg(http://img1c.xgo-img.com.cn/pics/1843/b1842753.jpg,getWH);function getWH(){    set(this.width, this.height)}function loadingImg(url,fun){    var _Img = new Image();    _Img.src = url;    /*判断是否已加载*/    (_Img.complete) ? fun : _Img.onload = fun;}function set(w,h){    console.log(w,h)}</script></body></html>