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

帮忙看看这段js,文字的移动速度时快时慢,图片也是
文字移动和图片移动在同一个页面
文字移动:
HTML code

<div id="demoabc" style="overflow:hidden;width:720px;height:18px; padding-bottom:2px; line-height:18px;  white-space:nowrap;">
        <div id="demoabc1">
        <%=gonggaoinfo%>
        </div>
        <div id="demoabc2"></div>
    </div>




JScript code

<script type="text/javascript">
   
    var demoabc2 = document.getElementById("demoabc2");
    var demoabc1 = document.getElementById("demoabc1");
    var demoabc = document.getElementById("demoabc");
    function MarqueeLeft() {
        if (demoabc2.offsetWidth - demoabc.scrollLeft  <= 0)
            demoabc.scrollLeft -= demoabc1.offsetWidth
        else {
            demoabc.scrollLeft++
        }
    }
    var MyMar1 = setInterval(MarqueeLeft, 20);
</script>



图片移动:
HTML code

<div class="top43" id="demo" style="overflow:hidden; width:930px; height: 170px">
<table cellspacing="0" cellpadding="0" align="left" border="0">
<tbody><tr>
<td id="demo1" style="width: 198px">
<table cellspacing="0" cellpadding="0" border="0">
<tbody><tr>

<asp:Repeater ID="rptgd" runat="server" >
         <ItemTemplate>
         <td>
           <div class="top44">
            <div class="top45">
             <div class="top46">
             <a href='cp3.aspx?id=<%#Eval("id") %>'>
            <img alt="" src='<%#Eval("entiroImagePath")%>' width="182" height="125" />
            </a>            
             
             </div>
            </div>
            <div class="top47"><a href='cp3.aspx?id=<%#Eval("id") %>'><%#Eval("entiroImageName")%></a></div>
           </div>          
           
        </td>      
         
      </ItemTemplate>     
      </asp:Repeater> 
          
<%--循环显示 END--%>
</tr></tbody>       
</table>
</td>
<td id="demo2" valign="top"></td>
</tr></tbody>
</table>
</div>



JScript code

<script type="text/javascript">
    var dir = 1//每步移动像素,数大为快
    var speed = 20//循环周期(毫秒)数大为慢
    demo2.innerHTML = demo1.innerHTML
    function Marquee() {//正常移动
        //alert(demo2.offsetWidth+"\n"+demo.scrollLeft)
        if (dir > 0 && (demo2.offsetWidth - demo.scrollLeft) <= 0) demo.scrollLeft = 0
        if (dir < 0 && (demo.scrollLeft <= 0)) demo.scrollLeft = demo2.offsetWidth
        demo.scrollLeft += dir
        demo.onmouseover = function () { clearInterval(MyMar) } //暂停移动
        demo.onmouseout = function () { MyMar = setInterval(Marquee, speed) } //继续移动
    }
    function r_left() { if (dir = -1) dir = 1 } //换向左移
    function r_right() { if (dir = 1) dir = -1 } //换向右移
    var MyMar = setInterval(Marquee, speed)
</script>




------解决方案--------------------
<script type=&quo