vue实现极简swiper

10 篇文章 0 订阅

极简swiper

效果图

在这里插入图片描述

HTML

<template>
		<div class="swiperModule">
			<div class="swiper_container">
				<div
					class="slide_item"
					:style="{transform: `translateX(${ 300 * (index - (activeIndex - 1)) }px) scale(${index === (activeIndex - 1) ? 1 : 0.83})`}"
					v-for="(item, index) in list" :key="index">
					<img :src="require(`../assets/images/${index + 1}.jpg`)" class="slideImg" alt="">
				</div>
			</div>
			<span class="swiperBtn leftBtn" @click="pre"> &lt; </span>
			<span class="swiperBtn rightBtn" @click="next"> &gt; </span>
		</div>
</template>

script

<script >
export default {
		name: "zh-swiper",
		data() {
				return {
					activeIndex: 1,
					directive: 0,
					list: [1, 2, 3, 4, 5, 6, 7]
				}
		},
		components: {},
		methods: {
			pre() {
				this.directive = -1;
				if (this.activeIndex >= 2) {
					this.activeIndex = this.activeIndex - 1;
				}
			},
			next() {
				this.directive = 1;
				if (this.activeIndex < this.list.length) {
					this.activeIndex = this.activeIndex + 1;
				}
			}
		}
}
</script>

css

<style >
.swiperModule {
	position: relative;
	width: 300px;
	height: 160px;
	border: 1px solid #ccc;
	margin: 0 auto;
}
.swiper_container {
	width: 300px;
	height: 160px;
	position: relative;
	overflow: hidden;
}
.slide_item {
	width: 300px;
	height: 160px;
	position: absolute;
	left: 0;
	top: 0;
	z-index: 10;
	transition: all .8s ease;
}
.slideImg {
	width: 100%;
	height: 100%;
}
.swiperBtn {
	display: inline-block;
	width: 30px;
	height: 30px;
	line-height: 30px;
	text-align: center;
	position: absolute;
	top: 50%;
	border: 1px solid #dddddd;
	border-radius: 50%;
	cursor: pointer;
	transform: translateY(-50%);
}
.leftBtn {
	left: -50px;
}
.rightBtn {
	right: -50px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值