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

使用vue2写一个太极图,并且点击旋转

下面是我自己写的一个代码,命名有些不规范,大家不要介意。

<template><div class="qq"><div class="app" :style="{ transform: rotateStyle }"><div class="app1"><div class="app3"><div class="app5"></div></div></div><div class="app2"><div class="app4"><div class="app6"></div></div></div></div><!-- 点击按钮 --><button class="app7" @click="toggleRotation">点击开始/停止旋转</button></div>
</template><script>
export default {data() {return {rotationSpeed: 1, // 初始旋转速度rotationCount: 0, // 旋转次数isRotating: false, // 是否正在旋转animationFrameId: null // 用于保存 requestAnimationFrame 返回的 ID};},computed: {rotateStyle() {return `rotate(-${this.rotationCount * this.rotationSpeed}deg)`;}},methods: {toggleRotation() {if (this.isRotating) {this.stopRotation();} else {this.startRotation();}},startRotation() {this.rotationCount = 0; // 重置旋转次数this.isRotating = true; // 开始旋转this.rotate();},stopRotation() {this.isRotating = false; // 停止旋转cancelAnimationFrame(this.animationFrameId); // 清除动画帧},rotate() {if (this.isRotating) {this.rotationCount++;this.rotationSpeed *= 1.002; // 加速旋转this.animationFrameId = requestAnimationFrame(this.rotate);}}}
};
</script><style>
.qq {width: 800px;height: 800px;background-color: gray;display: flex;align-items: center;justify-content: center;
}.app {display: flex;width: 310px;height: 310px;align-items: center;justify-content: center;
}.app1 {width: 150px;height: 300px;background-color: black;border-radius: 150px 0 0 150px;
}.app2 {width: 150px;height: 300px;background-color: white;border-radius: 0 150px 150px 0;
}.app3 {width: 150px;height: 150px;background-color: black;border-radius: 50%;position: absolute;margin-left: 75px;display: flex;align-items: center;justify-content: center;
}.app4 {width: 150px;height: 150px;background-color: white;border-radius: 50%;position: absolute;margin-top: 150px;margin-left: -75px;display: flex;align-items: center;justify-content: center;
}.app5 {width: 50px;height: 50px;background-color: white;border-radius: 50%;}.app6 {width: 50px;height: 50px;background-color: black;border-radius: 50%;
}.app7 {margin-left: 100px;
}
</style>
  • 在 Vue.js 组件的 data 部分,定义了一些数据属性,包括 rotationSpeed(旋转速度)、rotationCount(旋转次数)、isRotating(是否正在旋转)和 animationFrameId(保存 requestAnimationFrame 返回的 ID)。
  • 通过 computed 属性 rotateStyle 计算样式,用于控制旋转的角度。
  • 定义了三个方法:
    • toggleRotation:切换旋转状态,如果正在旋转,则停止;如果未旋转,则开始。
    • startRotation:开始旋转,重置旋转次数,设置 isRotatingtrue,并调用 rotate 方法。
    • stopRotation:停止旋转,设置 isRotatingfalse,并清除动画帧。
    • rotate:递归调用的方法,用于模拟旋转动画。每次调用会增加旋转次数和旋转速度,然后通过 requestAnimationFrame 请求下一帧的调用。

相关文章:

  • postman测试导入文件
  • 多协议转换网关BL120ML实现Modbus、楼宇自控、电力协议转Modbus
  • html + css + js简单的项目
  • 项目工程下载与XML配置文件下载:EtherCAT超高速实时运动控制卡XPCIE1032H上位机C#开发(十)
  • python元类为类的全部方法添加装饰器
  • 2017年认证杯SPSSPRO杯数学建模B题(第二阶段)岁月的印记全过程文档及程序
  • #《AI中文版》V3 第 1 章 概述
  • linux之安装配置VM+CentOS7+换源
  • 如何通过系统命令排查账号安全?
  • 智慧文旅运营综合平台:重塑文化旅游产业的新引擎
  • LeetCode349. 两个数组的交集
  • 【Linux】第三十二站:命名管道
  • Qt5.12.0 与 VS2017 在 .pro文件转.vcxproj文件
  • easyui渲染隐藏域<input type=“hidden“ />为textbox可作为分割条使用
  • Linux如何将文件或目录打成rpm包? -- fpm打包详解
  • [Vue CLI 3] 配置解析之 css.extract
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • Docker入门(二) - Dockerfile
  • ECS应用管理最佳实践
  • ES6简单总结(搭配简单的讲解和小案例)
  • go append函数以及写入
  • leetcode386. Lexicographical Numbers
  • mysql_config not found
  • seaborn 安装成功 + ImportError: DLL load failed: 找不到指定的模块 问题解决
  • text-decoration与color属性
  • Yii源码解读-服务定位器(Service Locator)
  • 好的网址,关于.net 4.0 ,vs 2010
  • 老板让我十分钟上手nx-admin
  • 巧用 TypeScript (一)
  • 微服务框架lagom
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • ​520就是要宠粉,你的心头书我买单
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (Matalb分类预测)GA-BP遗传算法优化BP神经网络的多维分类预测
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • (四)docker:为mysql和java jar运行环境创建同一网络,容器互联
  • (一)C语言之入门:使用Visual Studio Community 2022运行hello world
  • (原創) 如何刪除Windows Live Writer留在本機的文章? (Web) (Windows Live Writer)
  • (转)Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
  • (转载)深入super,看Python如何解决钻石继承难题
  • .Net CoreRabbitMQ消息存储可靠机制
  • .net/c# memcached 获取所有缓存键(keys)
  • .Net多线程总结
  • .sh
  • @ResponseBody
  • [ 数据结构 - C++] AVL树原理及实现
  • [AIGC] Spring Interceptor 拦截器详解
  • [asp.net core]project.json(2)
  • [AX]AX2012 AIF(四):文档服务应用实例
  • [BT]小迪安全2023学习笔记(第15天:PHP开发-登录验证)
  • [BZOJ4016][FJOI2014]最短路径树问题
  • [HCTF 2018]WarmUp (代码审计)
  • [hdu 3746] Cyclic Nacklace [kmp]