请大佬看看,要怎么解决这个bug呢。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
<style>
img{border: none;}
#demo {
position: relative;
background: red;
overflow:hidden;
width: 500px;
}
#indemo {
float: left;
width: 800%;
}
#demo1 {
float: left;
}
#demo2 {
float: left;
}
</style>
<body>
<div id="demo">
<div id="indemo">
<div id="demo1">
<a href="#"><img src="img/1.png" border="0" /></a>
<a href="#"><img src="img/2.png" border="0" /></a>
<a href="#"><img src="img/3.png" border="0" /></a>
<a href="#"><img src="img/4.png" border="0" /></a>
<a href="#"><img src="img/5.png" border="0" /></a>
<a href="#"><img src="img/6.png" border="0" /></a>
</div>
<div id="demo2"></div>
</div>
</div>
<div>
<p id="tab"></p>
<p id="tab2"></p>
</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(){
document.getElementById('tab').innerHTML=tab.scrollLeft
document.getElementById('tab2').innerHTML=tab2.offsetWidth
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>
</body>
</html>
stone310