uniapp轮播图(swiper)

属性名类型默认值说明平台差异说明
indicator-dotsBooleanfalse是否显示面板指示点
indicator-colorColorrgba(0, 0, 0, .3)指示点颜色
indicator-active-colorColor#000000当前选中的指示点颜色
active-classStringswiper-item 可见时的 class支付宝小程序
changing-classStringacceleration 设置为 {{true}} 时且处于滑动过程中,中间若干屏处于可见时的class支付宝小程序
autoplayBooleanfalse是否自动切换
currentNumber0当前所在滑块的 index
current-item-idString当前所在滑块的 item-id ,不能与 current 被同时指定支付宝小程序不支持
intervalNumber5000自动切换时间间隔
durationNumber500滑动动画时长app-nvue不支持
circularBooleanfalse是否采用衔接滑动,即播放到末尾后重新回到开头
verticalBooleanfalse滑动方向是否为纵向
previous-marginString0px前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值app-nvue、字节跳动小程序不支持
next-marginString0px后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值app-nvue、字节跳动小程序不支持
accelerationBooleanfalse当开启时,会根据滑动速度,连续滑动多屏支付宝小程序
disable-programmatic-animationBooleanfalse是否禁用代码变动触发 swiper 切换时使用动画。支付宝小程序
display-multiple-itemsNumber1同时显示的滑块数量app-nvue、支付宝小程序不支持
skip-hidden-item-layoutBooleanfalse是否跳过未显示的滑块布局,设为 true 可优化复杂情况下的滑动性能,但会丢失隐藏状态滑块的布局信息App、微信小程序
disable-touchBooleanfalse是否禁止用户 touch 操作App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序(只在初始化时有效,不能动态变更)
touchableBooleantrue是否监听用户的触摸事件,只在初始化时有效,不能动态变更字节跳动小程序(uni-app 2.5.5+ 推荐统一使用 disable-touch)
easing-functionStringdefault指定 swiper 切换缓动动画类型,有效值:default、linear、easeInCubic、easeOutCubic、easeInOutCubic微信小程序、快手小程序
@changeEventHandlecurrent 改变时会触发 change 事件,event.detail = {current: current, source: source}
@transitionEventHandleswiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy},支付宝小程序暂不支持dx, dyApp、H5、微信小程序、支付宝小程序、字节跳动小程序、QQ小程序、快手小程序
@animationfinishEventHandle动画结束时会触发 animationfinish 事件,event.detail = {current: current, source: source}字节跳动小程序不支持

效果图 

 代码块部分

<template>
	<view class="backgroundBanner" :style="{backgroundColor:backColor}">
		<view class="banner">
			<swiper autoplay="true" :interval="2000" :duration="500" circular="true" indicator-active-color="#fff"
				easing-function="true" indicator-dots='true' @change="swiperChange">
				<swiper-item v-for="(item, index) in bannerList" :key="index">
					<image :src="item.url"></image>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bannerList: [{
						url: 'https://img-blog.csdnimg.cn/37fa214c6c744e4ba0fcb2233017c8f4.png',
						color: 'red'
					},
					{
						url: 'https://img-blog.csdnimg.cn/8717f0e8d2b64efebcdc9c506a39bd61.png',
						color: 'green'
					},
					{
						url: 'https://img-blog.csdnimg.cn/ae94ba1d709744e2a6e36eb7d981f0a9.png',
						color: 'blue'
					},
					{
						url: 'https://img-blog.csdnimg.cn/6cc01905e7e942bdadb574af1079ae15.png',
						color: '#F0AD4E'
					}
				],
				backColor: ''
			}
		},
		mounted() {
			this.backColor = this.bannerList[0].color;
		},
		methods: {
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.backColor = this.bannerList[index].color;
			},
		}
	}
</script>

<style>
	.backgroundBanner {
		padding: 30rpx 10rpx;
		box-sizing: border-box;
	}

	.banner {
		width: 95%;
		margin: 0 auto;
	}

	.banner swiper {
		height: calc(750rpx / 1.9); //calc(屏幕宽度 / (图片宽度 / 图片高度))
	}

	.banner image {
		width: 100%;
		height: 100%;
	}
</style>
  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值