2 回答
TA贡献1810条经验 获得超5个赞
你只需要额外的暂停。
0 秒:scans.src = structScan;
5秒:scans.src = funScan;
10秒:scans.style.display = "none"; imagesArray[0].style.display = "block";
var scans = document.getElementById("Scan");
var structScan = scans.getAttribute("struc-src");
var funScan = scans.getAttribute("fun-src");
scans.src = structScan;
setTimeout(() => {
scans.src = funScan;
}, 5000);
//everything below this line works
const numOfPictures = 5;
const picturesNumberLength = 3;
let imageIndex = 1;
let imagesArray = [];
const imagesContainer = document.getElementById("img-container");
for (let i = 1; i < numOfPictures + 1; i++) {
const img = document.createElement("img");
img.src = `https://via.placeholder.com/150x150&text=home${(i+"").padStart(picturesNumberLength,"0")}.png`;
img.classList.add("slides");
img.style.display = "none";
imagesContainer.appendChild(img);
imagesArray.push(img);
}
setTimeout(() => {
scans.style.display = "none";
imagesArray[0].style.display = "block";
setInterval(() => {
imagesArray[imageIndex].style.display = "block";
if (imageIndex > 0) imagesArray[imageIndex-1].style.display = "none";
else imagesArray[numOfPictures-1].style.display = "none";
imageIndex++;
if (imageIndex >= numOfPictures) imageIndex = 0;
}, 3000);
}, 10000);
<section id="img-container"></section>
<img id="Scan" struc-src="https://via.placeholder.com/150x150&text=img1.png" fun-src="https://via.placeholder.com/150x150&text=img2.png"/>
TA贡献1856条经验 获得超17个赞
将 html 移到 script 标记之外。您应该 <img id="Scan" struc-src="img1.png" fun-src="img2.png"/>
在上面的部分下方或内部添加。
添加回答
举报