前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Swiper做轮播图

Swiper做轮播图

作者头像
明知山
发布2020-09-03 10:53:27
1.3K0
发布2020-09-03 10:53:27
举报
在这里插入图片描述
在这里插入图片描述
<!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>swiper</title>
    <link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .swiper-slide {
        background-position: center;
        background-size: cover;
        width: 300px;
        height: 250px;
    }

    img {
        width: 100%;
        height: 100%;
    }
</style>

<body>
    <div class="swiper-container">
        <div class="swiper-wrapper"></div>
        <div class="swiper-pagination"></div>
    </div>
</body>
<script src="https://unpkg.com/swiper/js/swiper.min.js"> </script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script>
    var swiperList = ['http://pic.51yuansu.com/backgd/cover/00/05/31/5b6294989be88.jpg',
        'http://pic.51yuansu.com/backgd/cover/00/56/38/5c6cefa1cc2fb.jpg',
        'http://pic.51yuansu.com/backgd/cover/00/41/86/5becb3686e4e8.jpg',
        'http://pic.51yuansu.com/backgd/cover/00/03/66/5b5b0a492f035.jpg']

    var item = ""
    for (let i in swiperList) {
        item += `<div class="swiper-slide"><img src="${swiperList[i]}" alt=""></div>`
    }
    $('.swiper-wrapper').append(item)

    var swiper = new Swiper('.swiper-container', {
        keyboard: true,
        loop: true,
        autoplay: true,
        effect: 'coverflow',
        centeredSlides: true,
        slidesPerView: 'auto',
        coverflowEffect: {
            rotate: 0,
            stretch: -20,
            depth: 100,
            modifier: 1,
            slideShadows: true
        },
        observer: true,//修改swiper自己或子元素时,自动初始化swiper 
        observeParents: true,//修改swiper的父元素时,自动初始化swiper 
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
    });
</script>

</html>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档