美文网首页
swiper 响应式开发

swiper 响应式开发

作者: 宏_4491 | 来源:发表于2020-07-11 20:02 被阅读0次

1、轮播图需要响应式, 图片在移动端和pc端要正常显示
2、使用的是swiper插件

swiper中文网

  • 官方网站下载好swiper.mini.js 和swiper.js 并且引入项目中
  • 重点是在 slide-wrap 设置
    display: flex;
    justify-content: center;
    align-items: center;
  • img 设置 object-fit: contain;
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./swiper.min.css">
    <style type="text/css">
        body,
        html {
            font-size: 16px;
            margin: 0;
            padding: 0;
        }

        .slide-wrap {
            display: flex;
            justify-content: center;
            align-items: center; 
        }

        .slide-wrap img {
            object-fit: contain;
            width: 100%;
            height: 100%;
        }

        .introdution {
            position: absolute;
            width: 80%;
            color: #ffffff;
        }

        .introdution h2 {
            font-size: 20px;
            text-shadow: 0 0 10px #000000;
        }

        .introdution p {
            font-size: 12px;
            text-shadow: 0 0 10px #000000;
        }

        @media (min-width: 500px) {
            .introdution {
                width: 80%;
            }

            .introdution h2 {
                font-size: 30px;
                text-shadow: 0 0 10px #000000;
            }

            .introdution p {
                font-size: 16px;
                text-shadow: 0 0 10px #000000;
            }

        }

        @media (min-width: 700px) {
            .introdution {
                width: 60%;
            }

            .introdution h2 {
                font-size: 40px;
                text-shadow: 0 0 10px #000000;
            }

            .introdution p {
                font-size: 20px;
                text-shadow: 0 0 10px #000000;
            }
        }
    </style>
</head>
<body>
    <div class="">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <div class="slide-wrap">
                        <img src="./beermeet.png" alt="">
                        <div class="introdution">
                            <div style="width: 30%;">
                                <h2>IROW MAN</br>钢铁侠</h2>
                                <p>vjjshdfhsihsnkdvdhdbjdvjbdbvdbpshsihihi</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
        </div>
    </div>
</body>
</html>
<script src="./jquery-1.10.2.min.js"></script>
<script src="./swiper.min.js"></script>
<script>
    $(function () {
        //======轮播图初始化====
        var mySwiper = new Swiper('.swiper-container', {
            direction: 'horizontal', // 水平切换选项
            loop: true, // 循环模式选项
            autoplay: {
                autoplay: true, //自动播放
                delay: 5000, //自动切换的时间间隔,单位ms
                disableOnInteraction: false, //如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
            },
            // 如果需要前进后退按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        })

    })
</script>

相关文章

  • swiper 响应式开发

    1、轮播图需要响应式, 图片在移动端和pc端要正常显示2、使用的是swiper插件 swiper中文网 官方网站下...

  • Web工具&框架

    快速开发工具 bootstrap 响应式布局,移动设备优先bootstrap官网 Swiper 移动端滑动效果 S...

  • js基础(6)

    27、移动端响应式布局开发 响应式布局开发 1、什么是响应式布局开发?把我们开发完成的产品,能够让其适配不同的设备...

  • 响应式布局---bootstrap框架

    移动端WEB开发之响应式布局 1.0 响应式开发原理 1.1 响应式开发原理 就是使用媒体查询针对不同宽度的设备进...

  • “一套代码,三屏齐发”——响应式开发浅析

    响应式开发 响应式是什么? 它能帮我们做些什么? 我们该怎么应用?它能达到什么效果?工作之余,通过响应式开发,我梳...

  • 响应式开发

    响应式开发 响应式网站设计 -----Ethan Marcotte 第一章 响应式网站设计的三大技术成分 流动网格...

  • vue-awesome-swiper 响应式

    使用 vue-awesome-swiper 版本为 3.1.4 (对应的 swiper 版本为 swiper4) ...

  • Angular表单验证

    angular4里一个响应式编程的小例子 Angular2 响应式表单验证 Angular开发(十一)-关于响应式...

  • 响应式开发

    响应式布局 什么是响应式布局?可以让一个网站兼容不同分辨率设备的布局 为什么要使用响应式布局?给用户更好的视觉使用...

  • 响应式开发

    什么是响应式设计? 1.让一个网站可兼容不同分辨率的设备 2.给用户更好的视觉体验 响应式布局的优点和缺点 优点:...

网友评论

      本文标题:swiper 响应式开发

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