我在这个 Shopify 主题中有一个轮播,我正在尝试对其进行编辑以使其每 5 秒自动滚动到下一张幻灯片(而不必单击到下一张幻灯片)。
这是我用于轮播的内容:
//Carousel interaction
(function() {
if (document.getElementById('carousel-nav')) {
var slides = document.getElementById('carousel-images'),
slidesItems = slides.getElementsByTagName('li'),
nav = document.getElementById('carousel-nav'),
navItems = nav.getElementsByTagName('li'),
current = 0;
function showSlide(i) {
if (i != current && slidesItems[i]) {
slide = slidesItems[i];
slide.className += ' show';
setTimeout (function() {
slide.className = slide.className.replace('show', 'appear');
}, 1);
setTimeout(function() {
slidesItems[current].className = slidesItems[current].className.replace('current', '');
slide.className = slide.className.replace('appear', 'current');
current = i;
}, 300);
navItems[i+1].className += ' current';
navItems[current+1].className = navItems[current+1].className.replace('current', '');
if (i == 0) {
if (navItems[0].className.indexOf('disabled') == -1) {
navItems[0].className += ' disabled';
}
} else {
navItems[0].className = navItems[0].className.replace(' disabled', '');
}
var l = navItems.length - 1;
if (i == slidesItems.length - 1) {
if (navItems[l].className.indexOf('disabled') == -1) {
navItems[l].className += ' disabled';
}
} else {
navItems[l].className = navItems[l].className.replace(' disabled', '');
}
}
}
nav.onclick = function(e) {
e = e || window.event; e = e.target || e.srcElement;
e = getParentByTagName(e, 'A');
if (e) {
var action = e.getAttribute('data-action');
if (action == 'prev') {
showSlide(current - 1);
} else if (action == 'next') {
showSlide(current + 1);
} else {
showSlide(parseInt(action));
}
}
return false;
}
}
})();
有任何想法吗?我有点难过。
谢谢!