uni-app/微信小程序 实现图片或元素淡入淡出效果

如题:

直接上代码

html

	<view class="banner">
			<image :animation="current==0?showpic:hidepic"
				src="https://dalituiwechat.oss-cn-hangzhou.aliyuncs.com/wechat/swiper11.png" mode=""></image>
			<image :animation="current==1?showpic:hidepic"
				src="https://dalituiwechat.oss-cn-hangzhou.aliyuncs.com/wechat/swiper22.png" mode=""></image>
		</view>

js部分

需要在date中声明好

                current: 0,
                hidepic: null,
                showpic: null

因为是已进入就开始的,所以 要在生命周期中使用

	var animation = uni.createAnimation({}) //创建一个动画实例
			console.log(animation);
			//淡入
			animation.opacity(1).step({
				// delay:1000,
				duration: 500
			}) //描述动画

			this.showpic = animation.export()
			//输出动画
			//淡出
			animation.opacity(0).step({
				// delay: 1000,
				duration: 1000
			})
			this.hidepic = animation.export()

最后一部别忘了,要给需要淡入淡出的元素或者图片设置绝对定位

	.banner {
			width: 100%;
			height: 186rpx;
			position: relative;

			image {
				width: 100%;
				height: 100%;
				position: absolute;
			}
		}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值