当前位置: 首页 > 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 请求下一帧的调用。
http://www.lryc.cn/news/286783.html

相关文章:

  • 张量计算和操作
  • 【Spring Boot 3】【JPA】枚举类型持久化
  • SVN 常用命令汇总(2024)
  • K8S四层代理Service-02
  • 3、非数值型的分类变量
  • 国内免费chartGPT网站汇总
  • 【Alibaba工具型技术系列】「EasyExcel技术专题」实战研究一下 EasyExcel 如何从指定文件位置进行读取数据
  • java.security.InvalidKeyException: Illegal key size错误
  • python脚本,实现监控系统的各项资源
  • Flink处理函数(2)—— 按键分区处理函数
  • 服务器数据恢复—服务器进水导致阵列中磁盘同时掉线的数据恢复案例
  • npm或者pnpm或者yarn安装依赖报错ENOTFOUND解决办法
  • 学会使用ubuntu——ubuntu22.04使用Google、git的魔法操作
  • 【机组】计算机组成原理实验指导书.
  • 解决Sublime Text V3.2.2中文乱码问题
  • Oracle 12CR2 RAC部署翻车,bug避坑经历
  • 情绪共享机器:潜力与挑战
  • docker 安装python3.8环境镜像并导入局域网
  • 修复“电脑引用的账户当前已锁定”问题的几个方法,看下有没有能帮助到你的
  • vp9协议笔记
  • 信息检索与数据挖掘 | (九)Link Analysis(链接分析)
  • yarn的安装及使用教程
  • 最新AI系统ChatGPT网站H5系统源码,支持Midjourney绘画,GPT语音对话+ChatFile文档对话总结+DALL-E3文生图
  • 学会使用ubuntu——ubuntu22.04使用WebCatlog
  • (Arcgis)Python3.8批量裁剪利用shp文件裁剪tif栅格影像数据
  • 漏洞补丁修复之openssl版本从1.1.1q升级到1.1.1t以及python版本默认2.7.5升级到2.7.18新版本和Nginx版本升级到1.24.0
  • HCIP-BGP实验4
  • 数据挖掘笔记1
  • Spring RabbitMQ那些事(3-消息可靠传输和订阅)
  • 揭秘 Kafka 高性能之谜:一文读懂背后的设计精粹与技术实现