<script language="javascript">
var n=20;
td2.innerHTML=td1.innerHTML
var Mycheck
  function move()
    {
      if(td2.offsetWidth-div1.scrollLeft<=0)
          div1.scrollLeft-=td1.offsetWidth
      else
        {
         div1.scrollLeft++}
      Mycheck=setTimeout(move,n)
}
div1.onmouseover=function(){clearTimeout(Mycheck)}
div1.onmouseout=function(){Mycheck=setTimeout(move,n)}
move();
</script>
<div id="div1" style="overflow:hidden;width:100%;color:#FFFF">
  <table cellspace="0" cellpadding="0" align="left" border="0">
     <tr>
        <td id="td1" valign="top">
           <table width="1320" height="89" border="0" cellspace="0" cellpadding="0">
               <tr>
                   <td width="110" background="1.jpg"></td>
                   <td width="110" background="2.jpg"></td>
                    <td width="110" background="3.jpg"></td>
                   <td width="110" background="4.jpg"></td>
                   <td width="110" background="2.jpg"></td>
                   <td width="110" background="3.jpg"></td>
                  <td width="110" background="4.jpg"></td>
                  <td width="110" background="1.jpg"></td>
                  <td width="110" background="2.jpg"></td>
               </tr>
           </table>
        </td>
        <td id="td2" valign="top">&nbsp;</td></tr></table>
</div> 
各位大侠帮看看,程序什么地方有问题了,运行的时候图片不滚动啊?

解决方案 »

  1.   

    <script>块放到最后。<div id="div1" style="overflow:hidden;width:1320;color:#FFFF"> <!-- width要小于td1的宽度 -->
      

  2.   

    slowhand大哥,你说的方法,小弟我有试,但是还是不成功啊
      

  3.   

    chinmo大哥,谢谢你的资料,我是想知道我列出来的代码什么地方不对
      

  4.   

    怎么会还不行呢?看一下是否你在浏览器把JS脚本功能禁了?
    我这里可以<div id="div1" style="overflow:hidden;width:1320;color:#FFFF"> 
      <table cellspace="0" cellpadding="0" align="left" border="0"> 
        <tr> 
            <td id="td1" valign="top"> 
              <table width="1320" height="89" border="0" cellspace="0" cellpadding="0"> 
                  <tr> 
                      <td width="110" background="1.jpg"> 1</td> 
                      <td width="110" background="2.jpg"> 2</td> 
                      <td width="110" background="3.jpg"> 3</td> 
                      <td width="110" background="4.jpg"> 4</td> 
                      <td width="110" background="2.jpg"> 5</td> 
                      <td width="110" background="3.jpg"> 6</td> 
                      <td width="110" background="4.jpg"> 7</td> 
                      <td width="110" background="1.jpg"> 8</td> 
                      <td width="110" background="2.jpg"> 9</td> 
                  </tr> 
              </table> 
            </td>
            <td id="td2" valign="top">&nbsp; </td> </tr> </table> 
    </div>
    <script language="javascript"> 
    var n=2; 
    td2.innerHTML=td1.innerHTML 
    var Mycheck 
      function move() 
        { 
          if(td2.offsetWidth-div1.scrollLeft <=0) 
              div1.scrollLeft-=td1.offsetWidth 
          else 
            { 
            div1.scrollLeft++} 
          Mycheck=setTimeout(move,n) 

    div1.onmouseover=function(){clearTimeout(Mycheck)} 
    div1.onmouseout=function(){Mycheck=setTimeout(move,n)} 
    move(); 
    </script>
      

  5.   


    这回可以了,原来你的意思是把<script></script>的部分放在后面,多谢指导!!!
    可是为什么放在后面就行,前面就失败呢?
      

  6.   

    在我的那个博客里也有说明了执行顺序的问题
    如果你放在前面找不到DIV的ID
    还有你这个写法不兼容
    要想兼容的 话,看我博客里的代码
      

  7.   

    这样每次用的时候需要修改javascript中很多东西,看看这个:
    http://blog.bossma.cn/javascript/javascript-flexible-scroll-words-or-images/这个程序可以自己设置水平(左右)、垂直(上下)滚动,设置滚动时间间隔和每次滚动距离,并且兼容多种浏览器用起来也很简单:
    <html>
    <head>
    <title>图片向左滚动</title>
    <script type="text/javascript" src="bossma-jscroll.js"></script>
    <script type="text/javascript">
    window.onload=function(){
    //参数依次为:滚动方向,滚动速度,容器ID,容器宽度,容器高度,滚动内容宽度,滚动内容高度,滚动步长
    var scroll =new JScroll("left",30,"content",558,165,1674,165,1);
    scroll.Start();
    };
    </script>
    </head>
    <body>
    <div id="title" style="width:100%;height:40px;">图片向左滚动</div>
    <div id="content">
    <!--
    滚动元素内部的水平排列需要自己来写,不要写到容器div(比如这里的id:content)的样式中。
    -->
    <div style="float:left"><img src="images/1.png" /></div>
    <div style="float:left"><img src="images/2.png" /></div>
    <div style="float:left"><img src="images/3.png" /></div>
    </div>
    <div id="foot"></div>
    </body>
    </html>