为什么点击没效果
制作轮播图然后点击没效果
制作轮播图然后点击没效果
2017-04-25
window.onload = function(){ var g = function(idx) { return document.getElementById(idx); } var container = g('container'), list = g('list'), buttons = g('buttons').getElementsByTagName('span'), prev = g('prev'), next = g('next'), index = 1; function showBtn() { var i = 0, len = buttons.length; for(;i<len;) { if(buttons[i].className == 'on') { buttons[i].className = ''; } i++; } buttons[index - 1].className = 'on'; } function animate(offset) { var newLeft = parseInt(list.style.left) + offset; list.style.left = newLeft + 'px'; if(newLeft > -600) { list.style.left = -3000 + 'px'; } if(newLeft < -3000) { list.style.left = -600 + 'px'; } } next.onclick = function () { if(index >= buttons.length) { index = 1; } else { index += 1 } animate(-600); showBtn(); //list.style.left = parseInt(list.style.left) - 600 + 'px'; } prev.onclick = function(){ if(index <= 1) { index = buttons.length; } else { index -= 1; } animate(600); showBtn(); //list.style.left = parseInt(list.style.left) + 600 + 'px'; } }
举报