vue2移动端+swiper实现异形的slide方式
作者:黛玉戴玉逮鱼
这篇文章主要介绍了vue2移动端+swiper实现异形的slide方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
在Vue2中安装及使用Swiper
安装swiper
npm install swiper@4.5.1 --save-dev
在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;
}
}实现效果
效果图如下:

效果类似:
Swiper演示中的“实现异形的slide”
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
