<!--下面是向左滚动代码--><div id="colee_left" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="colee_left1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
<td><p><img src="http://www.alixixi.com/images/noimg.gif"></p></td>
</tr>
</table>
</td>
<td id="colee_left2" valign="top"></td>
</tr>
</table>
</div>
<script>
//使用div时,请保证colee_left2与colee_left1是在同一行上.
var speed=30//速度数值越大速度越慢
var colee_left2=document.getElementById("colee_left2");
var colee_left1=document.getElementById("colee_left1");
var colee_left=document.getElementById("colee_left");
colee_left2.innerHTML=colee_left1.innerHTML
function Marquee3(){
if(colee_left2.offsetWidth-colee_left.scrollLeft<=0)//offsetWidth 是对象的可见宽度
colee_left.scrollLeft-=colee_left1.offsetWidth//scrollWidth 是对象的实际内容的宽,不包边线宽度
else{
colee_left.scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
colee_left.onmouseover=function() {clearInterval(MyMar3)}
colee_left.onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}
</script><!--向左滚动代码结束-->
那个为什么要进行colee_left2.offsetWidth-colee_left.scrollLeft<=0 这个判断
还有为什么要设置colee_left.scrollLeft这个?

解决方案 »

  1.   

    scrollLeft 设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离。
    即colee_left它的横向滚动条距左边框的距离colee_left.scrollLeft++;//使滚动条向右滚动,colee_left1的内部逐渐被隐藏,colee_left2的内容逐渐被显示但是当colee_left2全部被显示,colee_left1全部被隐藏的时候(即colee_left的滚动条达到最大的时候),colee_left2.offsetWidth-colee_left.scrollLeft<=0时
    我们要重新开始
    colee_left.scrollLeft-=colee_left1.offsetWidth