JS实现div自动滚动
1<div id="show" style="overflow:hidden;height:210px;">
2</div>
3<script>
4function startmarquee(lh,speed,delay){
5 var t;
6 var oHeight = 210; /**//** div的高度 **/
7 var p=false;
8 var o=document.getElementById("show");
9 var preTop = 0;
10 o.scrollTop = 0;
11 function start(){
12 t=setInterval(scrolling,speed);
13 o.scrollTop += 1;
14 }
15 function scrolling(){
16 if(o.scrollTop%lh!=0 && o.scrollTop%(o.scrollHeight-oHeight-1)!=0){
17 preTop = o.scrollTop;
18 o.scrollTop+=1;
19 if(preTop >= o.scrollHeight || preTop==o.scrollTop){
20 o.scrollTop = 0;
21 }
22 }else{
23 clearInterval(t);
24 setTimeout(start,delay);
25 }
26 }
27 setTimeout(start,delay);
28}
29startmarquee(20,20,1500);
30/**//**startmarquee(一次滚动高度,速度,停留时间);**/
31</script>
32