当前位置: 首页 > news >正文

uni-app使用CSS实现无限旋转动画

本来想用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>

http://www.lryc.cn/news/172225.html

相关文章:

  • java面向对象(八)
  • 【proverif】proverif的下载安装和初使用
  • 浙江大学《乡村振兴战略下传统村落文化旅游设计》许少辉八一著作——2023学生开学季辉少许
  • Centos7.9 一键脚本部署 LibreNMS 网络监控系统
  • 【大数据之Kafka】十六、Kafka集成外部系统之集成Flume
  • java学习--day3 (运算符、if循环、switch-case结构)
  • ActiveMQ、RabbitMQ、RocketMQ、Kafka区别
  • csp初赛总结 那些年编程走过的坑 初高中信竞常考语法算法点
  • DollarTree(美元树)验厂需要注意哪些方面?
  • vector使用和模拟实现
  • token登录的实现
  • GO语言从入门到实战-Go语言课程介绍
  • 七天学会C语言-第六天(指针)
  • 2023年腾讯云轻量服务器测评:16核 32G 28M 配置CPU测试
  • macos (M2芯片)搭建flutter环境
  • Xilinx FPGA未使用管脚上下拉状态配置(ISE和Vivado环境)
  • 数据结构---链表(java)
  • Qt --- Day02
  • Redis 集合(Set)快速指南 | Navicat
  • 【华为云云耀云服务器L实例评测】- 云原生实践,快捷部署人才招聘平台容器化技术方案!
  • 【Java】泛型 之 什么是泛型
  • Python yaml 详解
  • RabbitMQ消息可靠性(二)-- 消费者消息确认
  • 【python第7课 实例,类】
  • RocketMQ源码解析(上)
  • Webpack打包CSS文件,解决You may need an appropriate loader to handle this file type报错
  • 轮换对称性
  • 【MySQL基础】--- 约束
  • ROS2 的行为树 — 第 1 部分:解锁高级机器人决策和控制
  • kafka事务的详解