为什么我多次点击按钮图片越来越快,下面是我的代码 ,请大神帮忙解决下
/* ---------- 图片轮播 ---------------- */
var prev=document.getElementById('prev');
var next=document.getElementById('next');
var aImg=document.getElementById('aImg');
var btm=document.getElementById('bottom');
var span=btm.getElementsByTagName('span');
var onoff=false;
var num=0;
var timer = null;
var main=document.getElementById('main_real_right_box5');
var shopicde=false;
function showpic(offset){
onoff = true;
var newleft = parseInt(aImg.style.left)+offset;
var time = 300;
var Interval = 10;
var speed = offset/(time/Interval)
function go(){
if((speed<0 && parseInt(aImg.style.left) > newleft) || (speed>0 &&parseInt(aImg.style.left)<newleft) ){
aImg.style.left=parseInt(aImg.style.left) + speed + 'px';
setTimeout(go,Interval);
}
else{
onoff=false;
aImg.style.left=newleft+'px';
if(newleft>-580){
aImg.style.left=-2320+'px';
}
if(newleft<-2320){
aImg.style.left=-580+'px';
}
}
}
go();
}
/* aImg.style.left=newleft+'px'
if(newleft<-2320){
aImg.style.left=-580+'px'
}
if(newleft>-580){
aImg.style.left=-2320+'px'
}
}*/
function play(){
timer=setInterval(function(){
next.onclick()
},1000)
}
function stopon(){
clearInterval(timer);
}
prev.onclick=function(){
for(var i=0;i<span.length;i++){
span[num].className=''
}
if(num==0){
num=3
}else{
num-=1;
}
span[num].className='on'
showpic(580)
}
next.onclick=function(){
for(var i=0;i<span.length;i++){
span[num].className=''
}
if(num==3){
num=0
}else{
num+=1;
}
span[num].className='on'
showpic(-580);
}
for(var i=0;i<span.length;i++){
span[i].index=i;
span[i].onclick=function(){
for(var j=0;j<span.length;j++){
span[j].className=''
}
num = this.index;
span[num].className='on'
aImg.style.left=-580*(num+1)+'px'
}
}
/* ---------- 定时器 ---------------- */
main.onmouseover=stopon;
main.onmouseout=play;
play()
})