滚动函数

 1 <script language="javascript" type="text/javascript">
 2 window.onload=function(){
 3     var o=document.getElementById('box');
 4     var o2=document.getElementById('box2');
 5     window.setInterval(function(){scrollup(o,24,0);scrollup(o2,24,0)},3000)
 6 }
 7 ///滚动主方法
 8 ///参数:o 滚动块对象
 9 ///参数:d 每次滚屏高度
10 ///参数:c 当前已滚动高度
11 function scrollup(o,d,c){
12     if(d==c){
13         var t=getFirstChild(o.firstChild).cloneNode(true);
14         o.removeChild(getFirstChild(o.firstChild));
15         o.appendChild(t);
16         t.style.marginTop="0px";
17     }else{
18         c+=2;
19         getFirstChild(o.firstChild).style.marginTop=-c+"px";
20         window.setTimeout(function(){scrollup(o,d,c)},20);
21     }
22 }
23 //解决firefox下会将空格回车作为节点的问题
24 function getFirstChild(node){
25   while (node.nodeType!=1)
26   {
27          node=node.nextSibling;
28   }
29   return node;
30 }
31 </script>

 

posted @ 2013-09-09 12:30  鲤鱼在睡觉  阅读(303)  评论(0编辑  收藏  举报