判断childNodes.length 大于1的时候就滚动http://www.scriptlover.com

解决方案 »

  1.   

    先解释
    如果是一行的话,div1+div2总高是36,你设置的的又是36;height:36"> 所以就不存在滚动条(意思就是说和scrollTop没有关系)只有当 div.offsetHeight大于;height:36">才有关系!我给解决的办法
    <div id="div" style="overflow:hidden;height:36">
                <div id="div1">
                  <div>第一条</div>
                  <div>第二条</div>
                </div>
                <div id="div2"></div>
                <div id="div3"></div> 
          </div>
              <script>
      var speed        = 15;//滚动速度
      var rows        = 18;//每行高度
      var stim        = 80; //停留时间倍数 * speed
      var stop        = 0; //初始化值,不管
      div2.innerHTML    = div1.innerHTML
      div3.innerHTML    = div1.innerHTML
      function Marquee(){
        if(div.scrollTop%rows==0 && stop<=stim){
          stop++;
          return;
        }
        stop = 0;
        if(div2.offsetTop-div.scrollTop<=0)
          div.scrollTop-=div1.offsetHeight
        else{
          div.scrollTop++
        }
      }
      var MyMar       = setInterval(Marquee,speed)
      div.onmouseover = function() {clearInterval(MyMar)}
      div.onmouseout  = function() {MyMar=setInterval(Marquee,speed)}
    </script>
      

  2.   

    谢谢楼上两位。
    根据一楼的提示,基本达到我要的效果。
    二楼可能误解我的意思了,我是要上下滚动显示数据,而不是要显示滚动条。我的div1里面的数据是从数据库中动态读取的,按一楼的方法滚动一次就不滚了。再请帮忙解决,谢谢。<div id="div" style="overflow:hidden;height:500px">
      <div id="div1">
      <%
       set Rs = server.CreateObject("ADODB.Recordset")
            sql = "select * from tb"
         Rs.open sql,conn,1,1
     if not rs.eof then
     for i = 1 to rs.recordcount
     if rs.eof then exit for
      %>
      <div>
      <table width="100%" align="center" border="0" cellpadding="1" cellspacing="0">
                    <tr align="left">
    <td width="8%">No.<%=i%></td>
                      <td width="23%"><%=Rs("num1")%></td>
                      <td width="27%"><%=Rs("num2")%></td>
                      <td width="42%"><%=Rs("num3")%></td>
                    </tr>
                    <tr>
                      <td colspan="4"><img src="../main_images/pic_index_qt_line.gif" alt="" width="100%" height="1" /></td>
                    </tr>
    </table>
    <div>
    <%
      Rs.MoveNext
      next
      else
     response.Write("<div align=center style='margin-top:30px;font-size:18px;'>暂时没有----,请稍候!</div>")
     end if
     rs.close
     set rs = nothing
    %>
                  </div>
        <div id="div2"></div>
          </div>
    <script>
    <!--
      var speed = 15;//滚动速度
      var rows = 24;//每行高度
      var stim = 80; //停留时间倍数 * speed
      var stop = 0; //初始化值,不管
      if(document.getElementById('div1').childNodes.length>=20)
    {
      div2.innerHTML = div1.innerHTML;
      }
      function Marquee(){
        if(div.scrollTop%rows==0 && stop<=stim){
          stop++;
          return;
        }
        stop = 0;
        if(div2.offsetTop-div.scrollTop<=0)
          div.scrollTop-=div1.offsetHeight
        else{
          div.scrollTop++
        }
      }
      var MyMar    = setInterval(Marquee,speed)
      div.onmouseover = function() {clearInterval(MyMar)}
      div.onmouseout  = function() {MyMar=setInterval(Marquee,speed)}
    -->
    </script>