美文网首页
导航swiper切换

导航swiper切换

作者: Gaochengxin | 来源:发表于2017-11-16 14:00 被阅读233次
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="swiper.min.css"/><!--引入swiper.css-->
    <style type="text/css">
        .swiper-container{/*把主要的框写好*/
            width:400px;
            height:400px;
            border:1px solid #aaa;
        }
        .swiper-slide{/*轮播的内容*/
            width:100%;
            height:100%;
            text-align: center;
            line-height: 400px;
        }
        .swiper-pagination{/*装有小圆点的容器,把它移动到顶部,不过top为零时容易把内容覆盖一部分,所以减去小圆点的高度*/
            border-bottom: 1px solid #aaa;
            width:100%;
            height:40px;
            display: flex;
            top:0;
        }
        .swiper-pagination-bullet-active{/*这个是被选取得当前的小圆点的样式*/
            color:#808080;
        }
        .swiper-pagination-bullet{/*这个是小圆点的样式*/
            background:transparent;/*背景色设置为需要的背景*/
            -webkit-flex-grow: 1;/*这个就不用解释了吧,就是平均分配的弹性盒*/
            text-align: center;
            line-height: 40px;
            border-radius: 0;/*把小圆点重新设置为矩形*/
            height: 40px;
            color:#000000;
        }
        .swiper-pagination-bullet:nth-child(1):before{/*在元素的内容之前插入新内容;*/
            content:"Slide 1";/*所插入的内容*/
        }
        .swiper-pagination-bullet:nth-child(2):before{
            content:"Slide 2";
        }
        .swiper-pagination-bullet:nth-child(3):before{
            content:"Slide 3";
        }
        .swiper-pagination-bullet:nth-child(4):before{
            content:"Slide 4";
        }
        .swiper-pagination-bullet:nth-child(5):before{
            content:"Slide 5";
        }
    </style>
</head>
<body>
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
            <div class="swiper-slide">Slide 4</div>
            <div class="swiper-slide">Slide 5</div>
        </div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
    </div>
</body>
</html>
<script src="swiper.min.js" type="text/javascript" charset="utf-8"></script><!--引入swiper.js-->
<script type="text/javascript">
window.onload = function(){
        alert("请切换为手机模式")
    var swiper = new Swiper(".swiper-container", {
        pagination: ".swiper-pagination",//显示小圆点

        loop:true,                         //可以重复轮播,默认方式是false
        paginationClickable: true,         //值为真时,当单击指示器时会执行过渡动画到目标slide
        speed:300,                         //slides滑动动画之间的持续时间
        autoplayDisableOninteraction:true,//autoplay不会被禁掉,用户操作之后每次都会重新启动autoplay
//            mode:'horizontal',                 //slides滑动方式,水平或垂直
    });
   }
  </script>

相关文章

网友评论

      本文标题:导航swiper切换

      本文链接:https://www.haomeiwen.com/subject/ohulvxtx.html