• 2
  • function focusImage(interval) { var content = document.getElementById("focusImage-content").getElementsByTagName("li"); var tab = document.getElementById("focusImage-tab").getElementsByTagName("li"); var num = tab.length; var current = 0; var intervalObj; function init() { tab[0].className = "current"; content[0].className = "current"; for(var i = 0; i < tab.length; i++) { tab[i].onclick = function() { tabOnClick(this); } } intervalObj = window.setTimeout(scrollImage, interval * 1000); } function tabOnClick(liTag) { var i = parseInt(liTag.innerHTML) - 1; if(i == current) { return; } clearInterval(intervalObj); tab[current].className = "; content[current].className = "; tab[i].className = "current"; content[i].className = "current"; current = i; intervalObj = window.setTimeout(scrollImage, interval * 1000); } function scrollImage() { clearInterval(intervalObj); tab[current].className = "; content[current].className = "; current++; if(current >= num) { current = 0; } tab[current].className = "current"; content[current].className = "current"; intervalObj = window.setTimeout(scrollImage, interval * 1000); } init(); } new focusImage(3);