日期:2014-05-17  浏览次数:20456 次

这个js走马灯为什么不循环滚动
C# code


<div id="demoabc" style="overflow:hidden;width:710px;  white-space:nowrap;">
        <div id="demoabc1">
        <%=gonggaoinfo%>
        </div>
        <div id="demoabc2"></div>
    </div>
    
     
    <script type="text/javascript">
        var dirabc = 1//每步移动像素,数大为快
        var speedabc = 20//循环周期(毫秒)数大为慢
        demoabc2.innerHTML = demoabc1.innerHTML
        function Marqueeabc() {//正常移动
            //offsetWidth元素宽
            //scrollLeft页面利用滚动条滚动到右侧时,隐藏在滚动条左侧的页面的宽度
            if (dirabc > 0 && (demoabc2.offsetWidth - demoabc.scrollLeft) <= 0) demoabc.scrollLeft = 0
            if (dirabc < 0 && (demoabc.scrollLeft <= 0)) demoabc.scrollLeft = demoabc2.offsetWidth
            demoabc.scrollLeft += dirabc
           
            demoabc.onmouseover = function () { clearInterval(MyMarabc) } //暂停移动
            demoabc.onmouseout = function () { MyMarabc = setInterval(Marqueeabc, speedabc) } //继续移动
           
        }
        function r_leftabc() { if (dirabc = -1) dirabc = 1 } //换向左移
        function r_rightabc() { if (dirabc = 1) dirabc = -1 } //换向右移
        var MyMarabc = setInterval(Marqueeabc, speedabc)
       
</script>
  
     
     
     
 </div>




------解决方案--------------------
有滚动啊.可能是你的<%=gonggaoinfo%>内容太短.
或者你将width:710px改成width:50px可以看出有滚动.
------解决方案--------------------
参考:
http://www.cnblogs.com/insus/archive/2012/03/11/2389855.html