var step=5; var speed=200; var demo1=document.getElementById("demo1"); var demo2=document.getElementById("demo2"); var demo3=document.getElementById("demo3"); demo3.innerHTML=demo2.innerHTML; function autorun() { if(demo2.offsetHeight-demo1.scrollTop>=0) { demo1.scrollTop+=step; }else { demo1.scrollTop=0; } } setInterval("autorun()",speed);