您当前所在位置:    首页 > 代码集锦
返回
JS无间隙滚动[支持多个自定义滚动代码]
时间:2019-11-18    来自:臻心网络科技

jinshimove(d1,d2,d3,e,Cspeed)
d1 = 外围容器
d2 = 内容
d3 = 复制d2的内容接替循环滚动
e   = 方向与方法
   1,2,3,4 = 自动滚动,分别对应:上,右,下,左
   "top","right","bottom","left" = 手动滚动,分别对应:上,右,下,左

Cspeed=速度

--------------JS代码如下--------------

<script type="text/javascript">
function jinshimove(d1,d2,d3,e,Cspeed){ 
var speed = Cspeed;
    var demo=document.getElementById(d1); 
    var demo1=document.getElementById(d2); 
    var demo2=document.getElementById(d3); 
    demo2.innerHTML=demo1.innerHTML; 
    function boxTop(){ 
            if(demo2.offsetTop-demo.scrollTop<=0){demo.scrollTop-=demo1.offsetHeight} 
            else{demo.scrollTop++} 
        } 
    function boxRight(){ 
            if(demo.scrollLeft<=0){demo.scrollLeft+=demo2.offsetWidth} 
            else{demo.scrollLeft--} 
        } 
    function boxBottom(){ 
            if(demo1.offsetTop-demo.scrollTop>=0){demo.scrollTop+=demo2.offsetHeight} 
            else{demo.scrollTop--} 
        } 
    function boxLeft(){ 
            if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth} 
            else{demo.scrollLeft++} 
        } 
    if(e==1){ 
            var MoveTop=setInterval(boxTop,speed); 
            demo.onmouseover=function(){clearInterval(MoveTop);} 
            demo.onmouseout=function(){MoveTop=setInterval(boxTop,speed)} 
        } 

{nextpage}
    if(e==2){ 
            var MoveRight=setInterval(boxRight,speed); 
            demo.onmouseover=function(){clearInterval(MoveRight)} 
            demo.onmouseout=function(){MoveRight=setInterval(boxRight,speed)} 
        } 
    if(e==3){ 
            var MoveBottom=setInterval(boxBottom,speed); 
            demo.onmouseover=function(){clearInterval(MoveBottom);} 
            demo.onmouseout=function(){MoveBottom=setInterval(boxBottom,speed)} 
        } 
    if(e==4){ 
            var MoveLeft=setInterval(boxLeft,speed) 
            demo.onmouseover=function(){clearInterval(MoveLeft)} 
            demo.onmouseout=function(){MoveLeft=setInterval(boxLeft,speed)} 
        } 
    if(e=="top"){ 
            MoveTop=setInterval(boxTop,speed) 
            demo.onmouseout=function(){clearInterval(MoveTop);} 
        } 
    if(e=="right"){ 
            MoveRight=setInterval(boxRight,speed) 
            demo.onmouseout=function(){clearInterval(MoveRight);} 
        } 
    if(e=="bottom"){ 
            MoveBottom=setInterval(boxBottom,speed) 
            demo.onmouseout=function(){clearInterval(MoveBottom);} 
        } 
    if(e=="left"){ 
            MoveLeft=setInterval(boxLeft,speed) 
            demo.onmouseout=function(){clearInterval(MoveLeft);} 
        } 
    }   
</script>

{nextpage}
--------------调用代码如下--------------

<div id="v0" style="overflow:hidden;height:170px;width:790px;" align="center">
      <div id="v1">
        <div>
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              
              <td> <td><img src="5.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="4.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="5.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="4.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="5.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="4.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="5.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="4.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="5.gif" width="301" height="170" alt="" />
                
              <td> <td><img src="4.gif" width="301" height="170" alt="" />
                
              </tr>
          </table>
        </div>
      </div>
      <div id="v2"></div>
    </div>

<script type="text/javascript">jinshimove("v0","v1","v2",4,30);</script>

 
关注微信公众号
 

在线咨询

一键通话

联系我们