其他分享
首页 > 其他分享> > url加载图片,如何判断加载成功

url加载图片,如何判断加载成功

作者:互联网

img的complete属性

 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4     <meta charset="utf-8">
 5     <title>img - complete attribute</title>
 6 </head>
 7 <body>
 8     <img id="img1" src="http://pic1.win4000.com/wallpaper/f/51c3bb99a21ea.jpg">
 9     <p id="p1">loading...</p>
10     <script type="text/javascript">
11         function imgLoad(img, callback) {
12             var timer = setInterval(function() {
13                 if (img.complete) {
14                     callback(img)
15                     clearInterval(timer)
16                 }
17             }, 50)
18         }
19         imgLoad(img1, function() {
20             p1.innerHTML('加载完毕')
21         })
22     </script>
23 </body>
24 </html>

 

标签:function,complete,img,url,timer,callback,加载,图片
来源: https://www.cnblogs.com/huoshengmiao/p/15848704.html