【css酷炫效果】纯CSS实现粒子旋转动画

news/2025/3/22 4:47:43/

css酷炫效果】纯CSS实现粒子旋转动画

  • 创作背景
  • html结构
  • css样式
  • 完整代码
  • 效果图

想直接拿走的老板,链接放在这里:https://download.csdn.net/download/u011561335/90492008

创作随缘,不定时更新。

创作背景

刚看到csdn出活动了,赶时间,直接上代码。

html结构

	<div id="particle-container" class='particle-container'></div>

css_14">css样式

/* 基本样式重置 */
body, html {margin: 0;padding: 0;width: 100%;height: 100%;overflow: hidden; /* 防止滚动条出现 */background-color: #000; /* 设置背景颜色为黑色 */
}/* 粒子容器 */
.particle-container {position: relative;width: 100%;height: 100%;pointer-events: none; /* 使容器内的粒子不影响鼠标事件 */
}/* 粒子样式 */
.particle-container::before,
.particle-container::after,
.particle {content: '';position: absolute;top: 50%;left: 50%;width: 2px;height: 2px;background-color: rgba(255, 255, 255, 0.8); /* 设置粒子颜色为白色,带有一定的透明度 */border-radius: 50%;box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); /* 添加一些模糊效果 */animation: particleAnimation 5s infinite ease-in-out;pointer-events: none;
}/* 使用伪元素生成一些粒子 */
.particle-container::before,
.particle-container::after {width: 4px;height: 4px;
}/* 使用大量类生成更多粒子 */
.particle:nth-child(1) { top: 5%; left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { top: 15%; left: 20%; animation-delay: 0.2s; }
.particle:nth-child(3) { top: 25%; left: 30%; animation-delay: 0.4s; }/* 粒子动画关键帧 */
@keyframes particleAnimation {0% {transform: translate(-50%, -50%) rotate(0deg);opacity: 1;}100% {transform: translate(-50%, -50%) rotate(360deg) translate(200px, -200px);opacity: 0;}
}

完整代码

<!DOCTYPE html>
<html lang="en"> 
<head><title>页面特效</title>
<style type="text/css">
/* 基本样式重置 */
body, html {margin: 0;padding: 0;width: 100%;height: 100%;overflow: hidden; /* 防止滚动条出现 */background-color: #000; /* 设置背景颜色为黑色 */
}/* 粒子容器 */
.particle-container {position: relative;width: 100%;height: 100%;pointer-events: none; /* 使容器内的粒子不影响鼠标事件 */
}/* 粒子样式 */
.particle-container::before,
.particle-container::after,
.particle {content: '';position: absolute;top: 50%;left: 50%;width: 2px;height: 2px;background-color: rgba(255, 255, 255, 0.8); /* 设置粒子颜色为白色,带有一定的透明度 */border-radius: 50%;box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); /* 添加一些模糊效果 */animation: particleAnimation 5s infinite ease-in-out;pointer-events: none;
}@keyframes particleAnimation {0% {transform: translate(-50%, -50%) rotate(0deg);opacity: 1;}100% {transform: translate(-50%, -50%) rotate(360deg) translate(200px, -200px);opacity: 0;}
}</style></head>
<body><h1 style='color:red;'>斗破苍穹!</h1><div id="particle-container" class='particle-container'></div></body><script>const container = document.getElementById('particle-container');const numberOfParticles = 100;setInterval(function(){for (let i = 0; i < numberOfParticles; i++) {const particle = document.createElement('div');particle.classList.add('particle');particle.style.top = Math.random() * 95+ 'vh';particle.style.left = Math.random() * 95+ 'vw';particle.style.animationDelay = Math.random() * 5 * 0.4+`s`;particle.style.width = (Math.floor(Math.random() * 4) + 1)+`px`;particle.style.height = Math.floor(Math.random() * 4) + 1+`px`;container.appendChild(particle);}},3000);</script></html>

效果图

在这里插入图片描述


http://www.ppmy.cn/news/1581058.html

相关文章

当了5年牛马,我开始划水了。。。

我现在的这份工作&#xff0c;比上一份要好很多&#xff0c;首先薪资直接涨了一倍&#xff0c;7k到16.5k&#xff0c;13薪&#xff0c;朝九晚六&#xff0c;从不加班&#xff0c;项目也简单&#xff0c;包括我在内测试组一共有6个同事&#xff0c;但是每个人分到的任务真的很少…

lmbench测试方法

前言&#xff1a; 简介&#xff1a; Lmbench 是一款简易可以移植的内存测试工具&#xff0c;其主要功能有&#xff0c;带宽测评&#xff08;读取缓存文件、拷贝内存、读/写内存、管道、TCP&#xff09;&#xff0c;延时测评&#xff08;上下文切换、网络、文件系统的建立和删…

数据集获取

sklearn数据集 sklearn有四部分数据。其中sklearn的数据集有两部分真实的数据,一部分嵌入到了sklearn库中,即安装好sklearn后就自带了一部分数据,这些数据的规模比较小称为small toy datasets ,还有一部分数据是需要在网上下载的,sklearn提供了下载的api接口,这些数据规…

wangEditor富文本轻量使用及多个编辑器

0、官网 wangEditor multi editor 1、引入文件 <!--【富文本】第1步&#xff0c;引入--> <link rel"stylesheet" href"/wangeditor/style.css"/> <script charset"utf-8" src"/wangeditor/index.js"></script…

Pytest的夹具共享(2)

1、问题&#xff1a;夹具跟用例都是写在一个py文件中&#xff0c;在自动化框架中&#xff0c;测试用例、夹具在不同的文件中&#xff0c;跨文件夹具使用呢&#xff1f; “”" 在XXX测试用例模块中&#xff0c;使用夹具&#xff1f; 如何跨文件调用&#xff1f; -1&#x…

仿“东方甄选”直播商城小程序运营平台

在公域直播流量红利趋于饱和、流量成本大幅攀升的当下&#xff0c;私域直播为企业开辟了新的流量聚集和转化渠道&#xff0c;特别是对于那些希望在私域流量领域取得突破的品牌商家来说&#xff0c;直播场景以其独特的高频互动氛围&#xff0c;相比其他运营方式&#xff0c;展现…

DNS主从服务器

1.1环境准备 作用系统IP主机名web 服务器redhat9.5192.168.33.8webDNS 主服务器redhat9.5192.168.33.18dns1DNS 从服务器redhat9.5192.168.33.28dns2客户端redhat9.5192.168.33.7client 1.2修改主机名和IP地址 web服务器 [rootweb-8 ~]# hostnamectl hostname web [rootweb-8…

Harmony OS【获取本地json数据的方法】

// 文件名称 MapContent.json // 文件路径 resource/rawfile/MapContent.json [{"title": "准备与学习","brief": "加入HarmonyOS生态&#xff0c;注册成为开发者&#xff0c;通过HarmonyOS课程了解基本概念和基础知识&#xff0c;轻松开启…