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
	})
}
相关推荐
AFinalStone1 小时前
Android 7系统休眠唤醒(六)唤醒全链路
android·电源管理·休眠唤醒
用户059540174461 小时前
LangChain 记忆测试踩坑实录:这两个坑让我排查了 4 小时
前端·css
程序员黑豆1 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
用户938515635071 小时前
从零构建《天龙八部》知识库:EPUB 加载→文本分割→向量嵌入→Milvus 存储→RAG 问答,一条链路打通
javascript·人工智能·全栈
SamChan902 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
雨白2 小时前
深入理解 Kotlin 协程 (九):互通有无,解构 Channel 缓冲策略与底层无锁机制
android·kotlin
kyriewen2 小时前
AI Agent 9秒删光了生产数据库——我给自己的项目做了5个紧急检查
前端·ai编程·claude
IT_陈寒2 小时前
JavaScript的this又双叒叕让我怀疑人生了
前端·人工智能·后端
陈随易2 小时前
MCP协议第5次更新,从打电话到微信聊天的巨大变革
前端·后端·程序员
omnijk3 小时前
前端工程化
前端