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
	})
}
相关推荐
猫头虎-前端技术2 小时前
JS 作用域与闭包:从变量提升到闭包陷阱的超详细解析
开发语言·javascript·云计算·bootstrap·ecmascript·openstack·perl
2601_955767423 小时前
圆偏振光膜与AR抗反射膜原理评测:scinique双护技术如何实现“一柔一清”?
ios·ar·iphone·圆偏振光·磁控溅射
她说人狗殊途3 小时前
基于 vue-cli 创建
前端·javascript·vue.js
人月神话-Lee3 小时前
【图像处理】图像导出与工业级压缩策略——从像素到文件的最后一公里
图像处理·人工智能·ios·ai编程·swift
AZaLEan__4 小时前
前端移动端适配与 Bootstrap
前端·bootstrap·html
大家的林语冰4 小时前
Deno 2.8 正式发布,再次超越 Bun,史上最大的次版本升级诞生!
前端·javascript·node.js
渣渣xiong4 小时前
从零开始:前端转型AI agent直到就业第五十七天-第五十八天
前端·人工智能·python
影寂ldy4 小时前
C#数组的属性和方法(Clear / Copy / IndexOf )
开发语言·javascript·c#
Brave & Real5 小时前
小程序 const 在js中以及与同类的var和let之间的差异
javascript·微信小程序·小程序