uniapp组件-uni-transition过渡动画

过渡动画,通常用于元素的过渡效果,例如淡隐淡出效果,遮罩层的效果、放大缩小的效果等

一、基础过渡动画

<template>
	<view>
		<uni-section title="基础过渡动画" type="line"></uni-section>
		<view class="example-body">
			<button @click="open(['slide-top'])">slide-top</button>
			<button @click="open(['slide-left'])">slide-left</button>
			<button @click="open(['slide-right'])">slide-right</button>
			<button @click="open(['slide-bottom'])">slide-bottom</button>
			<button @click="open(['fade'])">fade</button>
			<button @click="open(['zoom-in', 'fade'])">zoom-in</button>
			<button @click="open(['zoom-out', 'fade'])">zoom-out</button>
		</view>
		<uni-transition :duration="500" :mode-class="modeClass" :styles="transfromClass" :show="transShow" @click="onTap">
			<text style="color: #fff;padding: 40px;background-color: #4CD964;">Test</text>
		</uni-transition>
	</view>
</template>

<script>
export default {
	components: {},
	data() {
		return {
			transShow: false,
			modeClass: ['fade'],
			maskClass: {
				position: 'fixed',
				bottom: 0,
				top: 0,
				left: 0,
				right: 0,
				'background-color': 'rgba(0, 0, 0, 0.4)'
			},
			transfromClass: {
				position: 'fixed',
				bottom: 0,
				top: 0,
				left: 0,
				right: 0,
				display: 'flex',
				'justify-content':'center',
				'align-items': 'center'
			}
		};
	},
	onLoad() {},
	methods: {
		open(mode) {
			this.modeClass = mode;
			this.transShow = !this.transShow;
		},
		onTap() {
			this.transShow =  false;
		}
	}
};
</script>

二、组合过渡动画

<template>
	<view>
		<view class="example-body">
			<button @click="open(['fade','zoom-out','slide-top'])">组合动画示例一</button>
			<button @click="open(['zoom-in','slide-bottom','fade'])">组合动画示例二</button>
			<button @click="open(['slide-left','slide-top','fade'])">组合动画示例三</button>
		</view>
		<uni-transition :mode-class="modeClass" :styles="transfromClass" :show="transShow" @click="onTap" :duration="500">
			<text style="color: #fff;padding: 40px;background-color: #4CD964;">Test</text>
		</uni-transition>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				transShow: false,
				modeClass: ['fade'],
				maskClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': 0,
					'left': 0,
					'right': 0,
					'background-color': 'rgba(0, 0, 0, 0.4)',
				},
				transfromClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': 0,
					'left': 0,
					'right': 0,
					'display': 'flex',
					'justify-content': 'center',
					'align-items': 'center'
				}
			}
		},
		onLoad() {},
		methods: {
			open(mode) {
				this.modeClass = mode
				this.transShow = !this.transShow
			},
			onTap() {
				this.transShow = this.show = false
			}
		}
	}
</script>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值