日期:2014-05-16  浏览次数:20379 次

图片左右滚动的,但是走一段时间就不走啦,请各位高手指教
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>左右翻滚的图片展示</title>
<style type="text/css">
*{margin:0;padding:0; text-align:center;}
  ul{list-style:none}
  #wrap{width:600px;border:1px solid orange;height:80px;overflow:hidden;}
  #a li,#b li{float:left;width:160px;height:60px;margin-left:10px line-height:80px;}
  #scrolls{width:200%;float:left;}
  #a,#b{float:left;}
  .left,.right{width:20px;height:20px;background:yellow;cursor:pointer;}
</style>
</head>
<body style="width:920px; weidth:60px;magrgin:0 auto; text-align:center; ">
<div class="left" id="left" onClick="left()"><<</div>
  <div id="wrap">
  <div id="scrolls">
  <div id="a">
  <ul>
  <li><img src="image/1.jpg" style="width:160px;height:60px;"/></li>
  <li><img src="image/2.jpg" style="width:160px;height:60px;"/></li>
  <li><img src="image/3.jpg" style="width:160px;height:60px;"/></li>
  <li><img src="image/4.jpg" style="width:160px;height:60px;"/></li>
  <li><img src="image/5.jpg" style="width:160px;height:60px;"/></li>
<li><img src="image/6.jpg" style="width:160px;height:60px;"/></li>
  </ul>
  </div>
  <div id="b"> </div>
  </div>
  <script type="text/javascript">
  var $ = function(id){return document.getElementById(id)};
  var wrap = $("wrap");
  var a = $("a");
  var b = $("b");
  var show = $("show");
  var d;
  b.innerHTML = a.innerHTML;
  function scrolls(){
  d = "n";
  if(b.offsetWidth - wrap.scrollLeft <=0){
  wrap.scrollLeft = wrap.scrollLeft - b.offsetWidth;
  }
  else{
  wrap.scrollLeft++;
  }
  }
   
  t = setInterval("scrolls()",10)
   
  function backScrolls(){
  if(wrap.scrollLeft <=0){
  wrap.scrollLeft = wrap.scrollLeft + b.offsetWidth;
  }
  else{
  wrap.scrollLeft--;
  }
  }
  function left(){
  d = "n";
  clearT();
  t = setInterval("scrolls()",10);
  }
  function right(){
  d = "m";
  clearT();
  t = setInterval("backScrolls()",10);
  }
  function clearT(){
  clearInterval(t);
  }
  function runs(){
  if(d == "n"){
  left();
  }
  else{
  right();
  }
  }
  wrap.onmouseover = function (){
  clearT();
  }
  wrap.onmouseout = function(){
  runs();
  }
  </script>