uniApp实现点赞动画效果

基于 uniapp+vue3组合式API+animation对象实现

<template>
	<view class="like-wrapper">
		<view class="icon" @click="handlelike">
			<image src="../../static/icon/点赞.svg" mode=""></image>
		</view>
		<view class="content" :animation="animationData" >
			+1
		</view>
	</view>
	
</template>

<script setup>
import { reactive, onMounted, onUnmounted, ref } from 'vue'
const animationData = ref({})
const animation = ref(null)

const handlelike = () => {
	// 实现点赞动画效果
	if (animation.value) {
		animation.value.translateY(-90).opacity(1).step({
			duration: 400
		});
		// 导出动画数据传递给组件的animation属性
		animationData.value = animation.value.export();
		// 还原动画
		setTimeout(()=>{
			animation.value.translateY(0).opacity(0).step({
				duration: 0
			});
			animationData.value = animation.value.export();
		},500)
	}
};

onMounted(() => {
	// 创建动画实例
	animation.value = uni.createAnimation();
	
});
onUnmounted(()=>{
	animationData.value = {}
});
</script>

<style lang="less">
	.like-wrapper{
		width: 100%;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		margin-top: 20upx;
		image{
			width: 150upx;
			height: 150upx;
		}
		.content{
			font-weight: 700;
			font-size: 20px;
			color: #ff0000;
			opacity: 0;
		}
	}
</style>

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值