侧边栏壁纸

Swiper实现轮播效果

2023年09月09日 798阅读 0评论 4点赞

swiper轮播 无所不能 主要还可以用来实现置顶文章轮播😀 正好本站也用上了

前端代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/css/swiper.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/js/swiper.js"></script>

    <style>
        .swiper-container {
            width: 600px;
            height: 400px;
        }
        .swiper-pagination-bullet-active {
            background-color: #fff;
        }
    </style>

</head>

<body>
    <div class="swiper-container">  <!-- 如果需要关闭手动控制滑动 把标签swiper-no-swiping添加进去-->
        <div class="swiper-wrapper">
        <!-- 这里放轮播的东西 图片文字都可以 -->
            <div class="swiper-slide"><img src="images/01.png" alt=""></div>
            <div class="swiper-slide"><img src="images/02.png" alt=""></div>
            <div class="swiper-slide"><img src="images/03.png" alt=""></div>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>
        <!-- 如果需要导航按钮 -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>
    </div>
    <script>
window.onload = function () {
    var mySwiper = new Swiper('.swiper-container', {
        // direction: 'horizonal',
        loop: true,
        autoplay: {
            delay: 2000,   // 轮播间隔时间
            stopOnLastSlide: false,
            disableOnInteraction: false,
            
        },
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
            clickable:true
        },

        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },

        // 如果需要滚动条
        scrollbar: {
            el: '.swiper-scrollbar',
        },
    })
}
    </script>
</body>

</html>

左右使用iconfont

.swiper-button-prev,.swiper-button-next{
            background: none;
        }
         .swiper-button-prev i,.swiper-button-next i{
            font-size:40px;
            color: aqua; 
        }
        
         <div class="swiper-button-prev"><i class="iconfont icon-left"></i></div>
        <div class="swiper-button-next"><i class="iconfont icon-zuoyoujiantou"></i></div>

小圆点

 .swiper-pagination-bullet-active {
             opacity: 1;
             background: #6ce68a;
          }
4
打赏

—— 评论区 ——

昵称
邮箱
网址
取消
站点公告

交流Q群:312955095

联系QQ:70027750

联系微信:xccx_cc

加好友备注来意,不备注不加~

人生倒计时
最新评论
舔狗日记