swiper切换 同时更换 背景色

前言:
最近做一个项目,甲方爸爸展示了一个案例,说轮播图切换的时候,同时背景色也要改变。所以,便写了一个demo。
话不多说,看效果图
在这里插入图片描述
直接上代码:

<template>
	<view class="content">
		<view class="swiper_bg" :style="swiperbg">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiper" @change="swiperChange">
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/bg1.jpg" mode="" mode="scaleToFill"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/bg2.jpg" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
			
	</view>
</template>
data() {
			return {
				swiperIndex:0,
				swiperbg:'background:'+'yellow'
			}
		},
methods: {
			swiperChange(e){
				this.swiperIndex=e.detail.current;
				if(this.swiperIndex==0){
					this.swiperbg='background:'+'yellow'
				} else {
					this.swiperbg='background:'+'blue'
				}
			}
		}

重点部分就在于change事件中,通过获取到index的值,来对style的属性进行赋值,赋予不同的背景颜色。

希望对你有所帮助!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值