uni-app:uni-transition动画分多个step执行(hbuilderx 3.7.3)
一,官方文档地址:
https://uniapp.dcloud.net.cn/component/uniui/uni-transition.html
二,js代码:
<template> <view> <view class="navBarBox" style="position: fixed;bottom:60px;z-index: 1000;"> <!-- 状态栏占位 --> <view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view> <!-- 导航栏内容 --> <view class="navBar" style="height:93rpx;"> <uni-transition ref="ani" :show="show" style="width:60rpx;height:60rpx;margin-left: 340rpx;display: flex; flex-direction: row;justify-content: center;align-items: center;"> <image class="heart" src="http://studyfile.nihonnoma.net/img/heart.png" :style="{ opacity: heartOpacity }" /> </uni-transition> <image ref="fav" :src="favSrc" style="position:absolute;width:60rpx;height:60rpx;margin-left: 120rpx;display: flex; flex-direction: row;justify-content: center;align-items: center;" @click="setfavorite" /> </view> </view> </view> </template> <script> export default { data() { return { show:true, favSrc:"http://studyfile.nihonnoma.net/img/heart_line.png", // 状态栏高度 statusBarHeight: 60, heartOpacity:0, //动画图的透明度 isMoving:0, //是否正在移动动画 isFavorited:0, //是否已收藏 } }, onLoad(option) { //获取手机状态栏高度 this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight']; }, methods: { //收藏或取消收藏 setfavorite() { if (this.isMoving == 1) { return false; } if (this.isFavorited == 1) { this.unfavorite(); } else { this.favorite(); } }, //收藏 favorite(){ this.isMoving = 1; this.show = true; this.heartOpacity = 1; this.reset(); setTimeout(()=>{ this.explode(); },50); setTimeout(()=>{ this.favSrc = "http://studyfile.nihonnoma.net/img/heart.png"; this.isMoving = 0; this.isFavorited = 1; this.heartOpacity = 0; },1050); }, //取消收藏 unfavorite(){ this.isMoving = 1; this.favSrc = "http://studyfile.nihonnoma.net/img/heart_line.png"; uni.showToast({ title:"已取消收藏", duration:500, }) setTimeout(()=>{ this.isMoving = 0; this.isFavorited = 0; },500); }, //重置动画元素 reset() { console.log(this.$refs.ani); this.$refs.ani.step({ translateY: '0rpx', scale:1, opacity: '1' }, { transformOrigin: '50% 50%', duration: 1 }); this.$refs.ani.run() }, //动画 explode() { //向上移动 this.$refs.ani.step({ translateY: '-800rpx', }, { timingFunction: 'ease-in', duration: 500 }); //变大和透明 this.$refs.ani.step({ scale:3, opacity: '0' }, { timingFunction: 'linear', duration: 500 }); //执行 this.$refs.ani.run() } } } </script> <style> .heart{ width:60rpx; height:60rpx; } </style>
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/05/uniapp-unitransition-dong-hua-fen-duo-ge-step-zhi-xing/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,查看效果
说明:收藏的心形向上滑动后再变大变透明
四,查看hbuilderx的版本:

分类:
uni-app
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-03-19 java 15: 查看jdk默认的gc和正在使用的gc
2022-03-19 java 15:配置gc log
2022-03-19 spring boot: 定时任务处理订单(spring boot v2.5.4)
2022-03-19 spring boot:分别在jar内部和外部使用配置文件(spring boot v2.5.4)
2020-03-19 centos8平台yum无法安装一些常用软件的解决,如:screen,iftop,nethogs
2020-03-19 centos8上配置openssh的安全