vue2移动端+swiper 实现异形的slide

目录

一、在Vue2中安装及使用Swiper

二、实现代码

三、实现效果

四、参考


一、在Vue2中安装及使用Swiper

1. 安装swiper

npm install swiper@4.5.1 --save-dev

2. 在main.js中引入

import 'swiper/dist/css/swiper.min.css';
import 'swiper/dist/js/swiper.min';

二、实现代码

以下分别是html、数据+swiper设置、样式的代码:

<template>
    <!-- 轮播图 -->
    <div class="swiper" id="swiper1">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item, index) in bookSwiper" :key="index">
          <img :src="item.img" class="bookImg" />
        </div>
      </div>
    </div>
</template>
<script>
import Swiper from 'swiper';

export default {
  name: "HomeView",
  data() {
    return {
      bookSwiper: [
        {
          img: "http://img.test.o2ting.com/ProductImages/2018/-0/20180206155502_726R.jpg_355x473.jpg",
          cntname: "错嫁良缘之一代军师",
        },
        {
          img: "http://iread.wo.com.cn/res/images/cover/lhsz/1491552645683/stream/smlf/image/cover.jpg",
          cntname: "鬼墓迷灯",
        },
        {
          img: "http://pic.qingting.fm/2017/0228/20170228173809513.jpg!medium",
          cntname: "九霄灵帝",
        },
      ],
    };
  },
  mounted() {
    new Swiper("#swiper1", {
      direction: "horizontal",
      speed: 600,
      loop: true,
      autoplay: false,
      observer: true,
      observeParents: true,
      effect: "coverflow",
      slidesPerView: "auto",
      centeredSlides: true,
      coverflowEffect: {
        rotate: 0, //slide做3d旋转时Y轴的旋转角度。默认50。
        stretch: -5, //每个slide之间的拉伸值,越大slide靠得越紧。 默认0。
        depth: 20, //slide的位置深度。值越大z轴距离越远,看起来越小。 默认100。
        modifier: 5,
        slideShadows: false, //开启slide阴影。默认 true。
      },
    });
  },
};
</script>
  // 轮播图
  .swiper {
    width: 100%;
    margin-bottom: 20px;

    .swiper-slide {
      width: 335px !important;
      height: 120px;
      font-size: 14px;
      text-align: center;
      line-height: 80px;
      border-radius: 8px;
      position: relative;
    }

    .bookImg {
      width: 335px !important;
      height: 120px;
      border-radius: 8px;
    }
  }

三、实现效果

1. 效果图如下:

2. 效果类似:Swiper演示中的“实现异形的slide”。

四、参考

vue使用异形swiper_书信成鸽1208的博客-CSDN博客_异形swiper

https://www.jianshu.com/p/ebfec766a99e

Swiper演示 - Swiper中文网

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值