html5应用swiper实现无缝轮播

注:移动端页面,如需用在PC端请自行调整样式
需要引入的代码

    <link rel="stylesheet" href="https://cdn.suoluomei.com/common/js2.0/swiper/v4.3.0/swiper.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <script src="https://cdn.suoluomei.com/common/js/jquery-2.1.4.min.js"></script>
    <script src="https://cdn.suoluomei.com/common/js2.0/swiper/v4.3.0/swiper.min.js"></script>

html代码

    <div class="srceem">
        
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide"><img class="lunboimg"
                        src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1307393608,1173558873&fm=26&gp=0.jpg">
                div>
                <div class="swiper-slide"><img class="lunboimg"
                        src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2898658313,1685012492&fm=26&gp=0.jpg">
                div>
                <div class="swiper-slide"><img class="lunboimg"
                        src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2970995881,3208967359&fm=26&gp=0.jpg">
                div>
                <div class="swiper-slide"><img class="lunboimg"
                        src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3197429252,593291742&fm=26&gp=0.jpg">
                div>
            div>
            
            <div class="swiper-button-next">div>
            <div class="swiper-button-prev">div>
            
            <div class="swiper-pagination">div>
        div>
    div>

script代码

    <!-- Swiper JS -->
    <script src="https://cdn.suoluomei.com/common/js2.0/swiper/v4.3.0/swiper.min.js"></script>

    <!-- Initialize Swiper -->
    <script>
        var swiper = new Swiper('.swiper-container', {
            spaceBetween: 30,
            loop: true,//实现无缝轮播
            autoplay: {
                delay: 2500,//每一次跳转的时间
                disableOnInteraction: false,
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            //左右按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        });
     
    </script>

style代码

  html,
        body {
            position: relative;
            height: 100%;
            background-color: #F1F1F5;
        }

        body {
            margin: 0;
            padding: 0;
        }

        .srceem {
            width: 100%;
            margin: 0;
        }

        .swiper-container {
            width: 100%;
            height: 12rem;
            background-color: black;
            display: flex;

        }

        .swiper-slide {
            text-align: center;
            /* Center slide text vertically */
            display: -webkit-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            -webkit-box-pack: center;
            -ms-flex-pack: center;
            -webkit-justify-content: center;
            justify-content: center;
            -webkit-box-align: center;
            -ms-flex-align: center;
            -webkit-align-items: center;
            align-items: center;
            z-index: 99;
        }

        .lunboimg {
            width: 100%;
            height: auto;
        }

效果图
html5应用swiper实现无缝轮播_第1张图片

你可能感兴趣的:(html)