任性不是罪
2016-07-19 09:35
window.onload = function(){ var container = document.getElementById('container'); var photos = document.getElementById('photos'); var buttons = document.getElementById('buttons'); var prev = document.getElementById('prev'); var next = document.getElementById('next'); var index = 1; function showButton(){ buttons[index-1].className = 'on'; } function animate(offset){ var newLeft = parseInt(photos.style.left) + offset; photos.style.left = newLeft + 'px'; if(newLeft > -600){ photos.style.left = -3000 + 'px'; } if(newLeft < -3000){ photos.style.left = -600 + 'px'; } } next.onclick = function(){ index += 1; showButton(); animate(-600); } prev.onclick = function(){ index -= 1; animate(600); showButton(); } }
就是加上圆点的函数后开始出错的。。。
var buttons = document.getElementById('buttons').getElementsByTagName("span");
这一句错了,获取的是buttons下面的五个按钮,而不是buttons。
焦点图轮播特效
65296 学习 · 611 问题
相似问题