1 回答

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
首先,復(fù)制第一張幻燈片并插入到末尾,然后復(fù)制最后一張幻燈片并插入到開頭:
var lastSlide = carousel_images[slidecount - 1].outerHTML;
var firstSlide = carousel_images[0].outerHTML;
carousel_slide.insertAdjacentHTML('afterbegin', lastSlide);
carousel_slide.insertAdjacentHTML('beforeend', firstSlide);
// Shift to the second slide:
carousel_slide.style.transform = `translateX(${-size}px)`;
當(dāng)您移至第一張幻燈片之前(最后一張幻燈片的副本)時(shí),您將等待動畫結(jié)束,然后默默地移至最后一張:
if (counter < 0) {
setTimeout(() => {
counter = carousel_images.length - 1;
carousel_slide.style.transition = "none";
carousel_slide.style.transform = `translateX(${-size * (counter + 1)}px)`;
}, 300);
}
當(dāng)您移至最后一張幻燈片(第一張的副本)之后的幻燈片時(shí),您會默默地移至第一張:
if (counter >= carousel_images.length) {
setTimeout(() => {
counter = 0;
carousel_slide.style.transition = "none";
carousel_slide.style.transform = `translateX(${-size}px)`;
}, 300);
}
工作演示:https://codepen.io/bortao/pen/MWwOVbd
- 1 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報(bào)