亲宝软件园·资讯

展开

JavaScript轮播图简单制作方法

carlyin 人气:0

本文实例为大家分享了JavaScript制作轮播图的具体代码,供大家参考,具体内容如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="js/jquery.js"></script>
  <style>
    .container{
      position: absolute;
      left: 0;
      top:0;
      width: 100%;
      overflow: hidden;
      border:1px solid #c3c3c3;
      border-radius: 4px;
    }
    .block1{
      margin:0;
      padding: 0;
      display: inline-block;
      height: 400px;
      background-color: #008800;
    }
    .block2{
      margin:0;
      padding: 0;
      display: inline-block;
      height: 400px;
      background-color: #ffff00;
    }
    .block3{
      margin:0;
      padding: 0;
      display: inline-block;
      height: 400px;
      background-color: #FF9900;
    }
  </style>
</head>
<body>
<div class="container" style="position: absolute;left: 0;top:0; width: 100%;height: 400px;">
  <div class="block1" style="position: absolute;left: 0;top:0;"></div>
  <div class="block2" style="position: absolute;left:0;top:0;"></div>
  <div class="block3" style="position: absolute; left:0;top:0;"></div>
</div>
</body>
<script>
  var wt=window.innerWidth;
  $(".block1").css({width:wt});
  $(".block2").css({width:wt,left:wt});
  $(".block3").css({width:wt,left:wt*2});
  var aa=setInterval(function(){
    $(".block1").css({left:parseFloat($(".block1")[0].style.left)-1});
    $(".block2").css({left:parseFloat($(".block2")[0].style.left)-1});
    $(".block3").css({left:parseFloat($(".block3")[0].style.left)-1});
    if($(".block3")[0].style.left=="0px"){
//      clearInterval(aa);
//      清除循环滚动
      $(".block1").css({left:0})
      $(".block2").css({left:wt})
      $(".block3").css({left:wt*2})
    }
  },2)
</script>
</html>

加载全部内容

相关教程
猜你喜欢
用户评论