普歌-知希团队:如何使用swiper插件实现轮播图自动播放(亲测有效)

一、swiper配置选项地址

从这里打开 https://www.swiper.com.cn/api/thumbs/2018/0916/432.html

或者直接搜索 swiper_Swiper参数选项

二、使用步骤

1.找到配置选项中的组件
2.点击自动切换(autoplay)
3.找到其中的mySwiper.autoplay.stop()

步骤图

三.查看 使用方法示例

<script language="javascript"> 
var mySwiper = new Swiper('.swiper-container',{
  autoplay : true,
})

//鼠标覆盖停止自动切换
mySwiper.el.onmouseover = function(){
  mySwiper.autoplay.stop();
}

//鼠标离开开始自动切换
mySwiper.el.onmouseout = function(){
  mySwiper.autoplay.start();
}
</script>

四.引入

注意!!!
这里引入的js和flexible都要放到 /body 的上面,所有html代码的底下,位置如下

</div>
    <script src="js/flexible.js">
    </script>
    <!-- 引入js文件 -->
    <script src="js/swiper-bundle.min.js"></script>
    <script>
        var mySwiper = new Swiper('.swiper-container', {
            pagination: {
                el: '.swiper-pagination',
                type: 'progressbar',
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            autoplay: {
                delay: 2000,
            } //1000,即1秒切换一次
        });
        // 鼠标停留停止切换
        mySwiper.el.onmouseover = function() {
            mySwiper.autoplay.stop();
        }

        //鼠标离开开始自动切换
        mySwiper.el.onmouseout = function() {
            mySwiper.autoplay.start();
        }
    </script>
</body>

</html>
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值