为什么我跟着老师写,还是错了?
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();
}
}就是加上圆点的函数后开始出错的。。。