注册 登录
编程论坛 ASP.NET技术论坛

淘宝轮播js 求助大神!!!!!

炎之言 发布于 2016-03-09 21:50, 5120 次点击
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus&reg;">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <style>
  body{width:100%;overflow-x:hidden;}
  #lun{background:red;position:absolute;}
  #lun img{float:left;}
  #bian{position:relative;margin:50px auto 0;background:yellow;overflow:hidden;}
  </style>
  <title>Document</title>
  <script>
  window.onload=function(){
      var a=0;
  var odiv1=document.getElementById('lun');
  var obian=document.getElementById('bian');
  var oli=odiv1.getElementsByTagName('img');
  odiv1.style.width=oli[0].offsetWidth*oli.length+'px';
  obian.style.width=oli[0].offsetWidth+'px';
  obian.style.height=oli[0].offsetHeight+10+'px';
  setInterval(function(){
      if(odiv1.offsetLeft<-oli[0].offsetWidth*oli.length){odiv1.style.left=0+'px';clearInterval(time);}
      else{a=a+oli[0].offsetWidth;han(-a);}
  },1000)
  }
  var timer=null;
  function han(it){
  var odiv1=document.getElementById('lun');
 clearInterval(timer);
  timer=setInterval(function(){
  var ispeed=(it-odiv1.offsetLeft)/8;
  ispeed=ispeed>0?Math.ceil(ispeed):Math.floor(ispeed);
  if(it==odiv1.offsetLeft){clearInterval(timer);}
  else{odiv1.style.left=odiv1.offsetLeft+ispeed+'px';}
  },30)
  }
  </script>
 </head>
 <body>
 <div id="bian">
 <div id="lun">
 <img src="e1.jpg" />
 <img src="e2.jpg" />
 <img src="e3.jpg" />
 <img src="e4.jpg" />
 </div></div>
 </body>
</html>


[此贴子已经被作者于2016-3-9 21:52编辑过]

0 回复
1