當前位置:成語大全網 - 新華字典 - html 圖片很多的情況下,怎樣實現先打開頁面,再慢慢加載?

html 圖片很多的情況下,怎樣實現先打開頁面,再慢慢加載?

<!DOCTYPE?HTML>

<html>

<head>

<title>Page?Title</title>

<meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8"?/>

<script>

onload?=?function()?{

var?imgs?=?document.querySelectorAll("img");

console.log("加載中...");

for?(var?i?=?0;?i?<?imgs.length;?i++)?{

var?img?=?imgs[i];

(function(i)?{

setTimeout(function()?{

img.src?=?"a"?+?i?+?".jpg";

img.onload?=?function(){

if(i?==?imgs.length?-?1){

console.info("加載完畢");

}

}

img.onerror?=?function(){

console.error("加載錯誤");

}

},?2000?*?i);

})(i);

}

}

</script>

</head>

<body>

<img?/>

<img?/>

<img?/>

<img?/>

</body>

</html>