From 32a7f45f9f3916613012c39171eeec2f3d9cff0c Mon Sep 17 00:00:00 2001 From: qq_36110571 Date: Wed, 18 Dec 2024 16:37:40 +0800 Subject: [PATCH] Auto Commit --- index.html | 4 ---- script.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 65297fe..2debf31 100644 --- a/index.html +++ b/index.html @@ -8,10 +8,6 @@ InsCode -
- InsCode -
欢迎来到 InsCode
-
111
diff --git a/script.js b/script.js index e69de29..2f7ec25 100644 --- a/script.js +++ b/script.js @@ -0,0 +1,44 @@ +window.onload = () => { + let total = 50; + const imageBox = document.getElementById('imageBox'); + + const imageUrls = Array.from( + {length: total}, + () => "https://yx5679.com/uploads/20241015/bce93d85b7455ff15a68ae539d61400a.jpg?t=" + Date.now() + ); + + // console.log(imageUrls); + function fetchImage(url) { + return fetch(url) + .then(response => { + if (!response.ok) { + throw new Error(`Failed to fetch ${url}: ${response.status}`); + } + return response.blob(); + }) + .catch(error => { + console.error(error); + return null; // 或者返回一个默认的图片 + }); + } + + function loadImages(urls) { + return Promise.all(urls.map(fetchImage)) + .then(images => { + // 处理加载完成的图片 + images.forEach((imageBlob, index) => { + // console.log(index); + if (imageBlob) { + const imgElement = document.createElement('img'); + imgElement.src = URL.createObjectURL(imageBlob); + !index && imageBox.appendChild(imgElement); + } + }); + }) + .catch(error => { + console.error('Error loading images:', error); + }); + } + + loadImages(imageUrls); +} \ No newline at end of file -- GitLab