问题补充说明:我做的是一个滚动图片,当鼠标移动到图片上时,图片停止滚动,离开继续滚动如果不加window.onload,在IE6下图片不滚动,但是加上window.onload后,在ie8,火狐,谷歌中,当鼠标移动到... 我做的是一个滚动图片,当鼠标移动到图片上时,图片停止滚动,离开继续滚动如果不加window.onload,在IE6下图片不滚动,但是加上window.onload后,在ie8,火狐,谷歌中,当鼠标移动到图片上时,图片仍然在滚动window.onload=function(){ setInterval(movePic,10); }; var mp=setInterval(movePic, 10); function movePic(){ var show=document.getElementById('show'); var mypic=document.getElementById('mypic'); var mypic2=document.getElementById('mypic2'); var w=mypic.offsetWidth; mypic2.innerHTML=mypic.innerHTML; if(mypic.offsetWidth-show.scrollLeft<=0){ show.scrollLeft-=mypic.offsetWidth; }else{ show.scrollLeft+=3; } } function stopMove(){ clearInterval(mp); } function keepMove(){ mp=setInterval(movePic, 10); }
你的代码写空未晚子转还值湖长的有问题。帮你改了:
window.onload=function(){mp=setInterval(movePic,10);
};
varmp=null;
functionmovePic(){
varshow=document.getElementById('show');
varmypic=document.g冷哥木坏值连etElementById('mypic');
v来自armypic2=360问答document.getElementById('mypic2');
varw=mypic.offsetWidth;
mypic2.innerHTML=mypic.innerHTML;
if(mypic.offsetWidth-show.scrollLeft<=0){
show.scrollLeft-井植绍成下于保=mypic.offsetWidth;
}else{
show.scrollLeft+=3;
}
}
functionstopMove(){
clearInterval(mp);
mp仍粒简=null;
}
functionkeepMove(){
if(mp){return;}
mp=setInterval(movePic,10);
}
标签:javascript,cl,earInterval