function Marquee(){
if(tab2.offsetWidth-tab.scrollLeft<=0)
tab.scrollLeft-=tab1.offsetWidth
else{
tab.scrollLeft++;
}
这一段给怎么理解呢、、、、
if(tab2.offsetWidth-tab.scrollLeft<=0)
tab.scrollLeft-=tab1.offsetWidth
else{
tab.scrollLeft++;
}
这一段给怎么理解呢、、、、
调试欢乐多
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<titel>图片无缝滚动</titel>
</head>
<body>
<style type="text/css">
#demo {
border:1px dashed #fda;
background-color: #fff;
overflow: hidden;
width:500px;
}
#demo img{
border:1px dotted #cca;
float: left;
}
#indemo {
float:left;
width:800%;
}
#demo1{
float:left;
}
#demo2{
float:left;
}
</style>
<div id="demo">
<div id="indemo">
<div id="demo1">
<a href="#"><img src="http://www.codefans.net/jscss/demoimg/wall7.jpg"/></a>
<a><img src="http://www.codefans.net/jscss/demoimg/wall5.jpg"/></a>
<a><img src="http://www.codefans.net/jscss/demoimg/wall3.jpg"/></a>
<a><img src="http://www.codefans.net/jscss/demoimg/wall4.jpg"/></a>
</div>
<div id="demo2">
</div>
</div>
<script>
var speed=10;
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 gunI=setInterval(Marquee,speed);
tab.onmouseover=function() {clearInterval(gunI);}
tab.onmouseout=function() {gunI=setInterval(Marquee,speed);}
</script>
</body>
</html>