<html>
<head>
<style type="text/css">
#top{width:900px;overflow:hidden;}
#con{height:340px;width:900px;width:2700px;}
#con div.demo{width:900px;height:340px;background:#ff99ff;float:left;}
</style>
</head>
<body>
  <div id="top">
<div id="con" style="margin-left:0;">
      <div class="demo" style="width:900px;"><p>testetestststs</p></div>
  <div class="demo" style="width:900px;"><p>setestsetsetsetest</p></div>
  <div class="demo" style="width:900px;"><p>testsettsetsetsets</p></div>
</div>
  </div>
  <script type="text/javascript">
  var $=function(ID){return document.getElementById(ID);}
  var speed=25;
  function scroll(){
    if(Math.abs(parseInt($("con").style.marginLeft))>=parseInt($("con").childNodes[0].style.width)){
  $("con").appendChild($("con").childNodes[0]);
  $("con").style.marginLeft="0px";
  clearTimeout(time);
  setTimeout(function(){time=setTimeout(scroll,speed);},2000);
} else {
  $("con").style.marginLeft=(parseInt($("con").style.marginLeft)-40)+"px";
  time=setTimeout(scroll,speed);
}
  }
  var time=setTimeout(scroll,speed);
  </script>  
</body>
</html>
貌似在chrome中无法运行~
求解..

解决方案 »

  1.   


      var $=function(ID){return document.getElementById(ID);}
      var speed=25;
      function scroll(){
        if(Math.abs(parseInt($("con").style.marginLeft))>=parseInt($("con").getElementsByTagName("div")[0].style.width)){
      $("con").appendChild($("con").getElementsByTagName("div")[0]);
      $("con").style.marginLeft="0px";
      clearTimeout(time);
      setTimeout(function(){time=setTimeout(scroll,speed);},2000);
    } else {
      $("con").style.marginLeft=(parseInt($("con").style.marginLeft)-40)+"px";
      time=setTimeout(scroll,speed);
    }
      }
      var time=setTimeout(scroll,speed);
    修改了下js,貌似chrome中可以正常运行~求批....
    感觉做的复杂了
      

  2.   

    ie9 chrome ff 下都没看见效果?
      

  3.   

    这样ie9 chrome ff sarafi都可以了
      

  4.   

    我在下面改了这句,貌似可以了chrome...