UNIAPP中NVUE页面 动画

UNIAPP中NVUE页面 动画

需要调用原生动画模块

javascript 复制代码
const animation = uni.requireNativePlugin('animation')

这里模拟一个刷新动画

html 复制代码
<image ref="refreshIcon" class="refresh" src="/static/icon/refresh.png" @click="getWeeklyOverviewFun()"></image>
javascript 复制代码
rotateAngle: 0, // 记录当前旋转角度
animationTimer: null,
isReshSportIcon: false,
				
async getWeeklyOverviewFun(from) {
	if (this.isReshSportIcon) return
	this.isReshSportIcon = true;
	this.startRotateAnimation()
	try {
		const res = await 获取服务端信息
	} catch (error) {
		console.error("失败:", error);
	} finally {
		this.stopRotateAnimation();
		this.isReshSportIcon = false;
	}
}
startRotateAnimation() {
	const rotateStep = () => {
			if (!this.isReshSportIcon) return
			this.rotateAngle += 360

			// 执行原生旋转动画
			animation.transition(this.$refs.refreshIcon, {
				styles: {
							transform: `rotate(${this.rotateAngle}deg)`,
							transformOrigin: 'center center'
				},
				duration: 1000, // 旋转一圈的时间(毫秒)
				timingFunction: 'linear' // 匀速旋转
			}, () => {
				// 动画完成后递归调用,实现无限循环
				rotateStep()
			})
	}
	rotateStep()
},
stopRotateAnimation() {
	this.isReshSportIcon = false;
	// 计算当前角度到0度的最短路径
	const currentAngle = this.rotateAngle % 360
	const targetAngle = this.rotateAngle + (360 - currentAngle)

	// 平滑转到0度后停止
	animation.transition(this.$refs.refreshIcon, {
			styles: {
				transform: `rotate(${targetAngle}deg)`,
				transformOrigin: 'center center'
			},
			duration: 300, // 归位动画时间
			timingFunction: 'ease-out'
	}, () => {
			this.rotateAngle = 0
	})
}
相关推荐
IT_陈寒29 分钟前
Vite静态资源路径这个大坑害我调了一下午
前端·人工智能·后端
狗哥哥35 分钟前
分享下我的读书清单
前端
合天网安实验室1 小时前
Log4J2 FilteredObjectInputStream RCE 漏洞分析
前端·黑客
两点王爷1 小时前
使用 GeoServer 发布 SHP 数据并在前端页面加载显示
前端
lhldsg1 小时前
全民健身解决方案软件开发实战:从架构设计到部署指南
java·前端·数据库·小程序
四六的六1 小时前
让 AI 自己去点后台页面,它把我们的库存点没了
前端·人工智能·agent·个人开发·ai编程·ai产品·ai前端
两点王爷1 小时前
Java 与前端加载 MVT 数据:从服务端切片到浏览器渲染
java·前端·状态模式
码农coding1 小时前
android12 状态栏图标的加载流程
android
小码过河.1 小时前
oceanbase中zone和observer、分区表之间关系
前端·数据库·oceanbase
hai_android2 小时前
Kotlin 协程作用域源码剖析
android·kotlin