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

使用js和css 实现div旋转围绕圆分布排列

记录,以防忘记

围绕圆

import React, { useEffect } from 'react';
import './index.scoped.scss';const Test = () => {const arr = Array.from({ length: 28 }, (_, index) => index + 1);useEffect(() => {const dayTotal = arr.length;// 动态设置每个点的旋转角度const dots = document.querySelectorAll('.dot') as NodeListOf<HTMLElement>;const pDeg = 360 / dayTotal;dots.forEach((dot, index) => {dot.style.transform = `rotate(${index * pDeg}deg) translate(0, -200px)`;});}, [arr.length]);return <div className='flex items-center justify-center w-full h-[100vh]'><div className='relative bg-gray-700 rounded-full box'>{arr.map((item, index) => {return <div key={index} className='absolute bg-blue-400 dot'>{item}</div>;})}</div></div>;
};export default Test;// scss$containSize: 400px;
$ballSize: 20px;.box {width: $containSize;height: $containSize;position: relative;.dot {width: $ballSize;height: $ballSize;position: absolute;top: 50%;left: 50%;margin-left: calc(-1 * $ballSize / 2);margin-top: calc(-1 * $ballSize / 2);transform-origin: center;}
}

进阶 实现loading加载

import React, { useEffect } from 'react';
import './index.scoped.scss';const Test = () => {const arr = Array.from({ length: 32 }, (_, index) => index + 1);return <div className='flex items-center justify-center w-full h-[100vh] bg-[#5bbff1]'><div className='relative rounded-full loading'>{arr.map((item, index) => {return <div key={index} className='absolute dot' />;})}</div></div>;
};export default Test;// scss$containSize: 150px;
$ballSize: 10px;.loading {width: $containSize;height: $containSize;$n: 32; // 小球数量$pDeg: calc(360deg / $n);   // 每个小球旋转的角度.dot {width: $ballSize;height: $ballSize;top: 0;left: 50%;margin-left: calc(-1 * $ballSize / 2);margin-top: calc(-1 * $ballSize / 2);transform-origin: center calc($containSize / 2) + calc($ballSize / 2);$duration: 2s; // 小球动画总时长@for $i from 1 through $n {&:nth-child(#{$i}) {transform: rotate(calc($i - 1) * $pDeg);&::after,&::before {animation-delay: -(calc($duration / $n * ($i - 1) * 6));}}}&::before,&::after {content: '';position: absolute;width: 100%;height: 100%;border-radius: 100px;}perspective: 70px;transform-style: preserve-3d;&::before {top: -100%;background: #000;animation: rotate-black $duration infinite;@keyframes rotate-black {0% {animation-timing-function: ease-in;}25% {transform: translate3d(0, 100%, $ballSize);animation-timing-function: ease-out;}50% {transform: translate3d(0, 200%, 0);animation-timing-function: ease-in;}75% {transform: translate3d(0, 100%, -$ballSize);animation-timing-function: ease-out;}}}&::after {top: 100%;background: #fff;animation: rotate-white $duration infinite;@keyframes rotate-white {0% {animation-timing-function: ease-in;}25% {transform: translate3d(0, -100%, -$ballSize);animation-timing-function: ease-out;}50% {transform: translate3d(0, -200%, 0);animation-timing-function: ease-in;}75% {transform: translate3d(0, -100%, $ballSize);animation-timing-function: ease-out;}}}}
}

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

相关文章:

  • SQL Server中CPU使用率过高的排查
  • AUTOSAR AP常用文档前缀
  • 服务器迁移基于Tomcat部署的java应用,没有源码怎么办?
  • kafka-go使用:以及kafka一些基本概念说明
  • 景联文科技:破解数据标注行业痛点,引领高质量AI数据服务
  • C#获取Network的相关信息
  • Jenkins 部署Vue项目指引: Vue项目本地跨域代理 、解决ERR_UNSAFE_PORT
  • C语言电子画板
  • Android Gradle开发与应用技术原理
  • Midjourney入门-提示词基础撰写与公式
  • Apache Tomcat服务器版本号隐藏
  • 【Qt】Qt编程注意事项
  • 在Linux系统安装Kafka
  • 【CSharp】简单定义一个异步方法
  • 贪心算法之货仓选址问题
  • Java网络编程——Request Response 对象
  • 【代码随想录训练营第42期 Day24打卡 回溯Part3 - LeetCode 93.复原IP地址 78.子集 90.子集II
  • python venv和virtualenv详解
  • 《征服数据结构》树堆(Treap)
  • 论文笔记:OneBit: Towards Extremely Low-bit Large Language Models
  • 英语文化中的音乐分类及其发展历史(Classical、Jazz、Rock、Pop、Electronic、Country、RB、Hip-Hop)
  • C语言-栈、队列、二叉树
  • pinia-plugin-persistedstate 插件不生效
  • sqlite 合并两个数据库中的特定表
  • winform中设置DateTimePicker参数为空
  • Python爬虫(8)
  • 靓图!多点创新!CEEMDAN-Kmeans-VMD-CNN-LSTM-Attention双重分解+卷积长短期+注意力多元时间序列预测
  • zdpgo_gin_limit 为zdpgo_gin打造的接口限流框架,当API接口需要限制访问频率的时候可以使用此框架
  • Java1234的Vue学习笔记
  • 嵌入式八股-C++面试91题(20240809)