vue3.x使用swiper 做卡片轮播

版本号:
vue/cli:4.5.12
swiper:^6.8.4

安装

npm install --save swiper

使用以及配置
<div class="swiper-container home_swiper">
	<div class="swiper-wrapper">
		<div class="swiper-slide" v-for="(item,index) in aImages" :key="index">
			<img :src="item.picUrl" alt="" />
		</div>
	</div>
</div>
import {
	ref,
	nextTick
} from 'vue';
import Swiper, {
	Autoplay,
	EffectCoverflow
} from "swiper";
Swiper.use([Autoplay, EffectCoverflow]);
import "swiper/swiper.scss";
export default {
	setup() {
		const aImages = ref([]);
		const fInitSwiper = () => {
			new Swiper(".home_swiper", {
				//循环
				loop: true,
				//每张播放时长3秒,自动播放
				spaceBetween: 16,
				// 切换效果 
				effect: "coverflow",
				// 该选项给Swiper用户提供小小的贴心应用,设置为true时,鼠标覆盖Swiper时指针会变成手掌形状,拖动时指针会变成抓手形状。
				grabCursor: true,
				// 设定为true时,active slide会居中,而不是默认状态下的居左。
				centeredSlides: true,
				// 设置slider容器能够同时显示的slides数量(carousel模式)。
				slidesPerView: 1.32,
				// 启动动态检查器(OB/观众/观看者),当改变swiper的样式(例如隐藏/显示)或者修改swiper的子元素时,自动初始化swiper。默认false,不开启,可以使用update()方法更新。
				observer: true,
				observeParents: true,
				observeSlideChildren: true,
				// 自动切换
				autoplay: {
					// 自动切换的时间间隔
					delay: 3000,
					// 如果设置为true,当切换到最后一个slide时停止自动切换
					stopOnLastSlide: false,
					// 用户操作swiper之后,是否禁止autoplay。默认为true:停止
					disableOnInteraction: false,
				},
				// 类似于苹果将多首歌曲的封面以3D界面的形式显示出来的方式
				coverflowEffect: {
					// slide做3d旋转时Y轴的旋转角度
					rotate: 0,
					// 每个slide之间的拉伸值,越大slide靠得越紧。5.3.6 后可使用%百分比
					stretch: -70,
					// slide的位置深度。值越大z轴距离越远,看起来越小。
					depth: 500,
					// depth和rotate和stretch的倍率,相当于depth*modifier、rotate*modifier、stretch*modifier,值越大这三个参数的效果越明显。
					modifier: 1,
					// 是否开启slide阴影
					slideShadows: true,
				},
			});
		};
		return {
			aImages 
		}
	}
}

展示效果

swiper-coverflow

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值