加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
Tomato 提交于 2024-04-04 22:27 . app修复
let nextDom = document.getElementById("next");
let prevDom = document.getElementById("prev");
let carouselDom = document.querySelector(".carousel");
let listItemDom = document.querySelector(".carousel .list");
let thumbnailDom = document.querySelector(".carousel .thumbnail");
nextDom.onclick = function () {
showSlide("next");
};
prevDom.onclick = function () {
showSlide("prev");
};
let timeRunning = 300;
let timeAutoNext = 5000;
let runTimeOut;
let runAutoRun = setTimeout(() => {
prevDom.click();
}, timeAutoNext);
function showSlide(type) {
let itemSlider = document.querySelectorAll(".carousel .list .item");
let itemThumbnail = document.querySelectorAll(".carousel .thumbnail .item");
if (type === "next") {
listItemDom.appendChild(itemSlider[0]);
thumbnailDom.appendChild(itemThumbnail[0]);
carouselDom.classList.add("next");
} else {
let positionLastItem = itemSlider.length - 1;
listItemDom.prepend(itemSlider[positionLastItem]);
thumbnailDom.prepend(itemThumbnail[positionLastItem]);
carouselDom.classList.add("prev");
}
clearTimeout(runTimeOut);
runTimeOut = setTimeout(() => {
carouselDom.classList.remove("next");
carouselDom.classList.remove("prev");
}, timeRunning);
clearTimeout(runAutoRun);
runAutoRun = setTimeout(() => {
prevDom.click();
}, timeAutoNext);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化