1 回答
TA贡献1880条经验 获得超4个赞
首先,复制第一张幻灯片并插入到末尾,然后复制最后一张幻灯片并插入到开头:
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)`;
当您移至第一张幻灯片之前(最后一张幻灯片的副本)时,您将等待动画结束,然后默默地移至最后一张:
if (counter < 0) {
setTimeout(() => {
counter = carousel_images.length - 1;
carousel_slide.style.transition = "none";
carousel_slide.style.transform = `translateX(${-size * (counter + 1)}px)`;
}, 300);
}
当您移至最后一张幻灯片(第一张的副本)之后的幻灯片时,您会默默地移至第一张:
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 关注
- 82 浏览
添加回答
举报