图片轮播的js

<script>
//轮播
$(function () {
    // var a = document.body.clientWidth;
    var a = 540;
    var x = 0;
    var timera = null;
    var firstimga = $('.imga').children().clone(); //克隆
    $('.imga').append(firstimga);
    $('.imga').css('width',5400+"px"); 

     $('.swiper-button-next').click(function () {
        x++;
        if (x == 6) {
            x = 1; //这里不是i=0
            $('.imga').css({left: 0}); //保证无缝轮播,设置left值
        }
        $('.imga').stop().animate({left: -x * a - 2});
        // alert(2)
    });
    // 上一个按钮
   $('.swiper-button-prev').click(function () {
    clearInterval(timera);
        x--;
        if (x == -1) {
            x = 6 - 2;
            $('.imga').css({left: -(6 - 1) * a});
        }
        $('.imga').stop().animate({left: -x * a - 2});
    })
    // 下一个按钮
    //定时器自动播放
    timera = setInterval(function () {
        x++;
        if (x == 6) {
            x = 0;
            $('.imga').css({left: 0});
        }
        $('.imga').stop().animate({left: -x * a}, 800);
    }, 2000)
    //鼠标移入,暂停自动播放,移出,开始自动播放
    $('.bannera').hover(function () {
        clearInterval(timera);
    }, function () {
        timera = setInterval(function () {
            x++;
            if (x == 6) {
                x = 1;
                $('.imga').css({left: 0});
            }
            $('.imga').stop().animate({left: -x * a}, 800);
        }, 2000)
    })

});

</script>

bootstrap实现图片轮播:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
  <style>
  /* Make the image fully responsive */
  .carousel-inner img {
      width: 100%;
      height: 100%;
  }
  </style>
</head>
<body>


<div id="demo" class="carousel slide" data-ride="carousel">
 
  <!-- 指示符 -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>
 
  <!-- 轮播图片 -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="http://static.runoob.com/images/mix/img_fjords_wide.jpg">
    </div>
    <div class="carousel-item">
      <img src="http://static.runoob.com/images/mix/img_nature_wide.jpg">
    </div>
    <div class="carousel-item">
      <img src="http://static.runoob.com/images/mix/img_mountains_wide.jpg">
    </div>
  </div>
 
  <!-- 左右切换按钮 -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
 
</div>


</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值