Marquee 连续滚动

在网上搜了一下几乎是同一个版本的连续滚动。并且有一些问题
于是就自己写了一个
   <div id="Parent" style="cursor: hand; overflow: hidden;  800px; height:50px">
       
<div id="Child_A" style="float:left;white-space:nowrap;"><a href="http://lookcode.net">lookcode</a> <a href="http://www.searoute.net">searoute</a>  </div>
    
</div>
    
<span id="spanMsg"></span>
    
<script type="text/javascript">
    var Parent 
= document.getElementById("Parent");
    var ChildA 
= document.getElementById("Child_A");
    var parentWidth 
= 800;
    var count
=2
    ChildA.innerHTML 
= ChildA.innerHTML + " " + ChildA.innerHTML;
    
while (Parent.scrollWidth<=parentWidth)
    
{    
        count 
*=2;
        ChildA.innerHTML 
= ChildA.innerHTML + " " + ChildA.innerHTML;
      
    }

    
var speed
=10;

function Marquee()
{
    
    
if (ChildA.offsetWidth/count-Parent.scrollLeft<0)//NB Cacluate the optimal position
    {
        Parent.scrollLeft 
-= ChildA.offsetWidth/count;
    }

    
else
    
{

        Parent.scrollLeft
++ 

    }

   
}

var MyMar
=setInterval(Marquee,speed)
Parent.onmouseover
=function() {clearInterval(MyMar)}
Parent.onmouseout
=function() {MyMar=setInterval(Marquee,speed)}
    
</script>

----write by lovebanyi 风云---
主要的是思想是利用滚条动。所以我们需要两个element 并且我们代码一定得让它产生滚动条。就是对同一个文本进行多次复制 这样子就OK了
第二就是计算出 重新开始的位置

把overflow设成scroll 这样就可以看到滚动条的效果了。   对spanMsg进行赋值可以观察

第四可以跟据代码做成你自己需要的向左向右向上向下。的代码
原文地址:https://www.cnblogs.com/lovebanyi/p/904458.html