求解释一段js代码,一直无法想明白marquee函数里 是啥意思
<div id="demo">
<script>
var speed = 50;
var tab = document.getElementById('demo');
var tab1 = document.getElementById('demo1');
var tab2 = document.getElementById('demo2');
tab2.innerHTML = tab1.innerHTML;
function Marquee() {
if (tab2.offsetWidth - tab.scrollLeft <= 0)
tab.scrollLeft -= tab1.offsetWidth
else {
tab.scrollLeft++;
}
}
var MyMar = setInterval(Marquee, speed);
tab.onmouseover = function() {
clearInterval(MyMar)
};
tab.onmouseout = function() {
MyMar = setInterval(Marquee, speed)
}; </script>
<div id="indemo">
<div id="demo1">
<ul>
<li>
<span class="sp3"><a href="product_d.html" ><img src="images/p1.jpg" onload="resize(this,170,136)" /></span>
<span class="sp4"><a href="#">展柜</a></span>
</li>
<li>
<span class="sp3"><a href="product_d.html" ><img src="images/p1.jpg" onload="resize(this,170,136)" /></span>
<span class="sp4"><a href="#">展柜</a></span>
</li>
<li>
<span class="sp3"><a href="product_d.html" ><img src="images/p1.jpg" onload="resize(this,170,136)" /></span>
<span class="sp4"><a href="#">展柜</a></span>
</li>
<li>
<span class="sp3"><a href="product_d.html" ><img src="images/p1.jpg" onload="resize(this,170,136)" /></span>
<span class="sp4"><a href="#">展柜</a></span>
</li>
</ul>
</div>
<div id="demo2"></div>
</div>
</div>
</div>
------解决方案--------------------function Marquee() {
if (tab2.offsetWidth - tab.scrollLeft <= 0) //tab2.offsetWidth:tab2的实际宽度,当tab.scrollLeft等于tab2.offsetWidth的时候说明tab1已经全部滚完了,于是回归原点
tab.scrollLeft -= tab1.offsetWidth//回归原点。其实这里写成tab.scrollLeft=0应该也是一样的,正常情况下tab2跟tab1是完全一样的。
else {
tab.scrollLeft++;//否则tab里的内容一直向左滚动。
&n