uni.createAnimation创建一个旋转动画,只能执行一次

本来想用uni.createAnimation创建一个旋转动画,发现转完一圈后就不动了,没法循环旋转,

后来又用setInterval每隔一个周期就把旋转角度加180度,发现运行一段时间后动画逐渐崩坏,应该是动画的周期和定时器的周期时间没有完全吻合导致的。

<image :animation="animationData" class="music_img_flag" src="../../static/images/musicflag.png"></image>
var animation = uni.createAnimation({
	duration: 2000,
	timingFunction: "linear"
});
this.stopAnimation()
this.timer = setInterval(() => {
	this.timeNum += 180;
	animation.rotate(this.timeNum).step();
	console.log('timeCheck:', this.timeNum)
	this.animationData = animation.export();
}, 2000);

最后采用了下面的这种方式,直接用CSS来实现循环旋转动画。

<view class="music_img_flag">
    <image src="../../static/images/musicflag.png"></image>
</view>
<style lang="scss" scoped>
		.music_img_flag {
			position: absolute;
			top: 202rpx;
			width: 88rpx;
			height: 88rpx;
 
			image {
				width: 100%;
				height: 100%;
				animation: animal 2s infinite linear;
				-webkit-animation: animal 2s infinite linear;
				-webkit-transform-origin: center center;
				-ms-transform-origin: center center;
				transform-origin: center center;
			}
 
			@keyframes animal {
				0% {
					transform: rotate(0deg);
					-ms-transform: rotate(0deg);
					-webkit-transform: rotate(0deg);
				}
 
				100% {
					transform: rotate(360deg);
					-ms-transform: rotate(360deg);
					-webkit-transform: rotate(360deg);
				}
			}
		}
</style>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值