内容是图片向左滚动,但是图片没有完全加载就执行JS了。导致滚动一遍就停了,怎么让一直滚动呢。<div id="jsweb8_cn_left" style="overflow:hidden;width:830px; margin-top:12px; float:left;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="jsweb8_cn_left1" valign="top" align="center">
<table cellpadding="5" cellspacing="5" border="0">
<tr align="center"><!--精品案例-->
<!--{foreach from=$case item=s}--><td class="pich" width="147" height="90"  ><a href="index.php?act=case_list&id={$s.id}"><img src="{$s.case_image}" border="0" width="147" height="90" ></a> </td>
<!--{/foreach}--></tr>
</table>
</td>
<td id="jsweb8_cn_left2" valign="top"></td>
</tr>
</table>
</div>
<!--向左滚动代码结束-->
</div>
{literal}
<script  type="text/javascript">var speed=30//速度数值越大速度越慢
//alert(document.getElementById('jsweb8_cn_left1').innerHTML);
document.getElementById('jsweb8_cn_left2').innerHTML=document.getElementById('jsweb8_cn_left1').innerHTMLfunction Marquee3(){if(document.getElementById('jsweb8_cn_left2').offsetWidth-document.getElementById('jsweb8_cn_left').scrollLeft<=0)
document.getElementById('jsweb8_cn_left').scrollLeft-=document.getElementById('jsweb8_cn_left1').offsetWidth
else{
document.getElementById('jsweb8_cn_left').scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
document.getElementById('jsweb8_cn_left').onmouseover=function() {clearInterval(MyMar3)}
document.getElementById('jsweb8_cn_left').onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}
</script>
{/literal}
</div>

解决方案 »

  1.   

    放到window.onload中
    window.onload=function(){var speed=30//速度数值越大速度越慢
    //alert(document.getElementById('jsweb8_cn_left1').innerHTML);
    document.getElementById('jsweb8_cn_left2').innerHTML=document.getElementById('jsweb8_cn_left1').innerHTMLfunction Marquee3(){if(document.getElementById('jsweb8_cn_left2').offsetWidth-document.getElementById('jsweb8_cn_left').scrollLeft<=0)
    document.getElementById('jsweb8_cn_left').scrollLeft-=document.getElementById('jsweb8_cn_left1').offsetWidth
    else{
    document.getElementById('jsweb8_cn_left').scrollLeft++
    }
    }
    var MyMar3=setInterval(Marquee3,speed)
    document.getElementById('jsweb8_cn_left').onmouseover=function() {clearInterval(MyMar3)}
    document.getElementById('jsweb8_cn_left').onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}}
      

  2.   

    有没有人帮帮忙啊。我加了
    <script language="javascript" type="text/javascript">if(document.readyState=="complete"){aa();}function aa(){你要执行的代码}</script>
    不过还是不好用。不知道是不是什么无缝连接的问题,。
      

  3.   

    谢谢2楼showbo。我试了。不行。所以我感觉可能不是加载的问题。是什么图片滚动时无缝连接的问题。所以放在静态页面里是好用的。程序加完后台就滚动一遍就停了。现在还反正来让我改。我哪会啊。急死了。
      

  4.   

    横向的话,把 jsweb8_cn_left 和 jsweb8_cn_left2 的宽度都设为 831 试试。overflow:hidden 改为 overflow:scroll
    仔细观察正常和一遍停止这2种情况有什么区别。
      

  5.   

    #5楼slowhand厉害厉害,改831好用了。咋来的这个数呢。我都整一天多了。再弄不出来今天交不了差了。呵。谢谢了。
      

  6.   

    晕。怎么我把overflow:hidden 改为 overflow:scroll后。再改回去就不好用了呢。
      

  7.   

    在IE的各个版本下都好用。在FF下无效果。
      

  8.   

     演示地址:http://www.popub.net/script/MSClass.html
     下载地址:http://www.popub.net/script/MSClass.js