html和css 实现元素顺时针旋转效果(椭圆形旋转轨迹)

devtools/2025/4/1 5:27:18/

一 实现效果

二 实现代码 

        我自己是用react写的。

        1. react 代码如下:

import React from "react";
import styles from "./index.less";export default () => {return <div className={styles.containers}><div className={styles.centerDiv}><svg width="200" height="100" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="textGradient" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" style={{stopColor: "red", stopOpacity: 1}}/><stop offset="100%" style={{stopColor: "yellow", stopOpacity: 1}}/></linearGradient><filter id="shadow" x="-50%" y="-50%" width="200%" height="200%"><feDropShadow dx="0" dy="6" stdDeviation="5" floodColor="rgba(0,0,0,0.5)"/></filter></defs><text x="60" y="30" fontSize="18" fontFamily="Arial" fill="url(#textGradient)" fontWeight={700}filter="url(#shadow)">这是中心点</text></svg></div><div className={styles.rotatingElement}>元素1</div><div className={styles.rotatingElement}>元素2</div><div className={styles.rotatingElement}>元素3</div><div className={styles.rotatingElement}>元素4</div><div className={styles.rotatingElement}>元素5</div><div className={styles.rotatingElement}>元素6</div><div className={styles.rotatingElement}>元素7</div><div className={styles.rotatingElement}>元素8</div><div className={styles.rotatingElement}>元素9</div><div className={styles.rotatingElement}>元素10</div><div className={styles.rotatingElement}>元素11</div><div className={styles.rotatingElement}>元素12</div><div className={styles.rotatingElement}>元素13</div></div>
}

2. css 代码如下:

css">
.containers {width: 100%;height: calc(100vh - 55px);background: #1677ff;display: flex;align-items: center;justify-content: center;.centerDiv {position: absolute;top: calc(50% - 60px);left: calc(50% - 90px);}
}.rotatingElement {position: absolute;width: 150px;height: 150px;left: 45%;top: 36%;transform-origin: 0 0;cursor: pointer;transition: background-color 0.3s;display: flex;justify-content: center;align-items: center;text-align: center;font-weight: 700;font-size: 20px;color: red;background: powderblue;border-radius: 50%;
}/* 为13个元素设置不同的初始角度和动画延迟 */
.rotatingElement:nth-child(2) {animation: orbit 40s linear infinite;animation-delay: 0s;
}.rotatingElement:nth-child(3) {animation: orbit 40s linear infinite;animation-delay: -3.08s;
}.rotatingElement:nth-child(4) {animation: orbit 40s linear infinite;animation-delay: -6.16s;
}.rotatingElement:nth-child(5) {animation: orbit 40s linear infinite;animation-delay: -9.24s;
}.rotatingElement:nth-child(6) {animation: orbit 40s linear infinite;animation-delay: -12.32s;
}.rotatingElement:nth-child(7) {animation: orbit 40s linear infinite;animation-delay: -15.4s;
}.rotatingElement:nth-child(8) {animation: orbit 40s linear infinite;animation-delay: -18.48s;
}.rotatingElement:nth-child(9) {animation: orbit 40s linear infinite;animation-delay: -21.56s;
}.rotatingElement:nth-child(10) {animation: orbit 40s linear infinite;animation-delay: -24.64s;
}.rotatingElement:nth-child(11) {animation: orbit 40s linear infinite;animation-delay: -27.72s;
}.rotatingElement:nth-child(12) {animation: orbit 40s linear infinite;animation-delay: -30.8s;
}.rotatingElement:nth-child(13) {animation: orbit 40s linear infinite;animation-delay: -33.88s;
}.rotatingElement:nth-child(14) {animation: orbit 40s linear infinite;animation-delay: -36.96s;
}/* 悬停效果 */
.rotatingElement::before {content: '';position: absolute;width: 100%;height: 100%;background: gold;border-radius: 50%;opacity: 0;transition: opacity 0.3s ease;z-index: 1;
}/* 悬停效果 */
.rotatingElement:hover::before {opacity: 1;
}/* 当任何旋转元素被悬停时,暂停所有旋转元素的动画 */
.containers:hover .rotatingElement {animation-play-state: paused !important;
}@keyframes orbit {0% {transform: translate(calc(530px * cos(0deg)), calc(290px * sin(0deg)));}10% {transform: translate(calc(530px * cos(36deg)), calc(290px * sin(36deg)));}20% {transform: translate(calc(530px * cos(72deg)), calc(290px * sin(72deg)));}30% {transform: translate(calc(530px * cos(108deg)), calc(290px * sin(108deg)));}40% {transform: translate(calc(530px * cos(144deg)), calc(290px * sin(144deg)));}50% {transform: translate(calc(530px * cos(180deg)), calc(290px * sin(180deg)));}60% {transform: translate(calc(530px * cos(216deg)), calc(290px * sin(216deg)));}70% {transform: translate(calc(530px * cos(252deg)), calc(290px * sin(252deg)));}80% {transform: translate(calc(530px * cos(288deg)), calc(290px * sin(288deg)));}90% {transform: translate(calc(530px * cos(324deg)), calc(290px * sin(324deg)));}100% {transform: translate(calc(530px * cos(360deg)), calc(290px * sin(360deg)));}
}


http://www.ppmy.cn/devtools/171368.html

相关文章

MySQL:数据库基础

数据库基础 1.什么是数据库&#xff1f;2.为什么要学习数据库&#xff1f;3.主流的数据库&#xff08;了解&#xff09;4.服务器&#xff0c;数据库&#xff0c;表之间的关系5.数据的逻辑存储6.MYSQL架构7.存储引擎 1.什么是数据库&#xff1f; 数据库(Database,简称DB)&#x…

RabbitMQ的高级特性介绍(二)

发送方确认 当消息的⽣产者将消息发送出去之后&#xff0c;消息到底有没有正确地到达服务器呢? 如果在消息到 达服务器之前已经丢失(比如RabbitMQ重启, 那么RabbitMQ重启期间⽣产者消息投递失败), 持久化操作也解决不了这个问题&#xff0c;因为消息根本没有到达服务器&#…

物联网系统部署与运维实训室

一、引言 在数字化时代&#xff0c;物联网技术正以前所未有的速度蓬勃发展&#xff0c;广泛渗透到各个领域&#xff0c;深刻改变着人们的生活和工作方式。从智能家居、智能交通到工业自动化、医疗健康等&#xff0c;物联网的应用无处不在&#xff0c;推动着各行业的智能化变革…

“零拷贝”(Zero-Copy)技术详解以及使用场景

“零拷贝”(Zero-Copy)是一种优化数据传输效率的技术,通过减少或消除数据在内存中的复制次数,显著提高I/O操作性能。以下是使用Java代码实现的零拷贝技术示例。 Java NIO 中的零拷贝实现 1. 内存映射文件(Memory Mapped File) import java.io.IOException; import jav…

工作记录 2017-03-07

工作记录 2017-03-07 序号 工作 相关人员 1 修改邮件上的问题。 更新RD服务器。 郝 更新的问题 1、增加了2个菜单Global Fee Category、Global Fee List。 2、增加了Global Fee Category页面。 3、增加了Global Fee List页面。 我在把邮件上的文件生成导入数据库…

硬件基础(5):(3)二极管的应用

文章目录 [toc]1. **整流电路****功能**&#xff1a;**工作原理**&#xff1a;**应用实例**&#xff1a;电路组成&#xff1a;整流过程&#xff1a;电路的应用&#xff1a; 2. **稳压电路****功能**&#xff1a;**工作原理**&#xff1a;**应用实例**&#xff1a;电路组成及功能…

提升生产效率的关键: ethercat转TCPIP网关智能通信

大家好。最近在数据互联互通方面&#xff0c;我们迎来了一个重要的突破。作为生产管理系统的核心组成部分&#xff0c;数据互联互通一直是一个亟待解决的挑战。我们知道&#xff0c;EtherCAT和TCP/IP是两种不同的通信协议&#xff0c;它们之间的互通性一直存在问题。 不过&…

Vulnhub靶场thales靶机通关攻略(一)

1.在Orcde VirtuaBox打开靶机 2.拿kali&#xff08;桥接模式&#xff09;扫描网段 22和8080端口开放 3.查看网站 需要登录&#xff0c;尝试爆破密码 4.使用msf对应模块找到密码&#xff0c;有对应模块 5.登录进入后台&#xff0c;发现上传文件部分 6.用msfvenom反弹shell ms…