zoukankan      html  css  js  c++  java
  • 轮播图,swiper使用

    背景:

      最近接到一个需求,重写首页,需要用到轮播图。

      但是轮播图只用两张图,此为前提。

      本想直接用ElementUI的走马灯,但是只用两张图的情况下,走马灯不能循环播放,只能来回播放,公司的UI小姐姐说这样不专业,所以用了swiper。

    正文:

      一年前用过swiper,但早忘了。我说一下这次使用的过程。

      1.装包

        npm install vue-awesome-swiper --save

      2.引入

      // require styles
      import 'swiper/dist/css/swiper.css'
      import { swiper, swiperSlide } from 'vue-awesome-swiper'

      3.使用

        <swiper :options="swiperOption">
            <!-- slides -->
            <swiper-slide>
              <img src="./1.png" alt="1" />
            </swiper-slide>
            <swiper-slide>
              <img src="./2.png" alt="2" />
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination"  slot="pagination"></div>
            <!-- <div class="swiper-button-prev" slot="button-prev"></div>
            <div class="swiper-button-next" slot="button-next"></div> -->
          </swiper>
    data() {
        return {
          // 轮播图参数
          swiperOption: {
            //滑动速度
            speed: 800,
            // // 指针形状
            // grabCursor : true,
            //循环
            loop: true,
            //自动播放
            autoplay: {
              // 自动切换的时间间隔,单位ms
              delay: 1500,
              // 用户操作swiper之后,是否禁止autoplay
              disableOnInteraction: false,
            },
            // 分页器
            pagination: {
              el: '.swiper-pagination',
              // 点击控制Swiper切换
              clickable :true,
            }
          }
        }
      },
      components: {
        swiper,
        swiperSlide
      }
     .container {
         100%;
        overflow: hidden;
        height: 500px;
        // 轮播图样式
        .swiper-container {
          height: 100%;
          .swiper-slide {
            img {
               100%;
              height: 100%;
            }
          }
        }
      }

    4.效果


    后续

      后来我又看elementui,两张图还是不能循环,但是两张图,复制一下就成了四张图。

      就可以循环了,然后,操作按钮之类的,可以根据elementui提供的回调函数修改。

    云在青天水在瓶。
  • 相关阅读:
    应用连接Redis报错处理
    粗谈RESTFul API接口-认识粗谈RESTFul API接口-认识
    策略模式有效解决过多的if-else
    slice的共享内存时需要注意的问题
    swoole中使用wss
    swoole版本和PHP版本的对应关系
    php中关于新引入object的坑
    Java Object Serialization Specification.
    php将索引数组转换成关联数组
    Gson解析json字符串的坑
  • 原文地址:https://www.cnblogs.com/mjwblog/p/11725562.html
Copyright © 2011-2022 走看看