CSS3-流星雨

news/2025/3/18 11:57:45

1. 绘制标签

<div class="container">
	<span></span>
</div>

2. 设置div背景

在百度上搜索一幅星空的图片

<style>css">
	* {
		/* 初始化 */
		margin: 0;
		padding: 0;
	}

	body {
		/* 高度100% */
		height: 100vh;
		/* 溢出隐藏 */
		overflow: hidden;
	}

	.container {
		background: url(xk1.jpg) no-repeat;
		width: 100%;
		height: 100%;
		position: absolute;
		/* 把背景图像扩展到足够大,使背景图像覆盖背景区域 */
		background-size: cover;
		/* 背景图像设置为正中间 */
		background-position: center;
	}
</style>

在这里插入图片描述

3. 绘制流星和尾巴

span {
	width: 10px;
	height: 10px;
	background-color: #fff;
	position: absolute;
	left: 50%;
	top: 50%;
	/* 圆角 */
	border-radius: 50%;
	/* 发光效果 
	0 x轴方向的长度
	0 y轴方向的长度
	10 阴影模糊度,只能为正数
	4  阴影的扩散半径				
	*/
	box-shadow: 0px 0 10px 4px rgba(255, 255, 255, 1);

}


span::before {
	content: "";
	width: 300px;
	height: 3px;
	/* 渐变背景 90度,由#fff 向完全透明渐变 */
	background: linear-gradient(90deg, #fff, transparent);
	position: absolute;
	top: 50%;
}

在这里插入图片描述

4. 添加背景缩放的动画

/* 定义动画 ,背景缩放*/
@keyframes animateBg {

	0%,
	100% {
		transform: scale(1);
	}

	50% {
		transform: scale(1.2);
	}
}

添加动画到 .container 的样式中
在这里插入图片描述

5. 流星动画

@keyframes animateLx {
	0% {
		/* 角度旋转315度,x方向移动0px */
		transform: rotate(315deg) translateX(0);
		opacity: 1;
	}

	90% {
		opacity: 1;
	}

	100% {
		/* 角度旋转315度,x方向移动-1000px 向左边移动 */
		transform: rotate(315deg) translateX(-1000px);
		opacity: 0;
	}
}

添加动画到span标签上
在这里插入图片描述

6. 为第一个span单独设置动画出现的位置,和动画效果

span:nth-child(1) {
	top: 0px;
	left: initial;
	right: 0px;
	/* 动画延迟时间 */
	animation-delay: 0s;
	/* 动画时长 */
	animation-duration: 1s;
}

请添加图片描述

7. 为第二个span单独设置动画出现的位置,和动画效果

span:nth-child(2) {
	top: 0px;
	right: 80px;
	left: initial;
	animation-delay: 0.1s;
	animation-duration: 3s;
}

在这里插入图片描述

请添加图片描述

8. 后续

每添加一个标记,就添加一个对应的样式,通过改变top ,right ,动画延时,动画时长等参数,生成不同的流星

请添加图片描述

9. 完整代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>流星雨划过天际的动画</title>
		<style>css">
			* {
				/* 初始化 */
				margin: 0;
				padding: 0;
			}

			body {
				/* 高度100% */
				height: 100vh;
				/* 溢出隐藏 */
				overflow: hidden;
			}

			.container {
				background: url(xk1.jpg) no-repeat;
				width: 100%;
				height: 100%;
				position: absolute;
				/* 把背景图像扩展到足够大,使背景图像覆盖背景区域 */
				background-size: cover;
				/* 背景图像设置为正中间 */
				background-position: center;

				/* 执行动画,时长,线性的,无限次数播放 */
				animation: animateBg 5s linear infinite;
			}

			span {
				width: 10px;
				height: 10px;
				background-color: #fff;
				position: absolute;
				left: 50%;
				top: 50%;
				/* 圆角 */
				border-radius: 50%;
				/* 发光效果 
				0 x轴方向的长度
				0 y轴方向的长度
				10 阴影模糊度,只能为正数
				4  阴影的扩散半径				
				*/
				box-shadow: 0px 0 10px 4px rgba(255, 255, 255, 1);
				animation: animateLx 3s linear infinite;

			}


			span::before {
				content: "";
				width: 300px;
				height: 3px;
				/* 渐变背景 90度,由#fff 向完全透明渐变 */
				background: linear-gradient(90deg, #fff, transparent);
				position: absolute;
				top: 50%;
			}

			/* 定义动画 ,背景缩放*/
			@keyframes animateBg {

				0%,
				100% {
					transform: scale(1);
				}

				50% {
					transform: scale(1.2);
				}
			}

			@keyframes animateLx {
				0% {
					transform: rotate(315deg) translateX(0);
					opacity: 1;
				}

				90% {
					opacity: 1;
				}

				100% {
					transform: rotate(315deg) translateX(-1000px);
					opacity: 0;
				}
			}

			span:nth-child(1) {
				top: 0px;
				right: 0px;
				left: initial;
				/* 动画延迟时间 */
				animation-delay: 0s;
				/* 动画时长 */
				animation-duration: 1s;
			}

			span:nth-child(2) {
				top: 0px;
				right: 80px;
				left: initial;
				animation-delay: 0.1s;
				animation-duration: 3s;
			}

			span:nth-child(3) {
				top: 80px;
				right: 0px;
				left: initial;
				animation-delay: 0.4s;
				animation-duration: 2s;
			}

			span:nth-child(4) {
				top: 0px;
				right: 10px;
				left: initial;
				animation-delay: 0.7s;
				animation-duration: 2s;
			}

			span:nth-child(5) {
				top: 0px;
				right: 400px;
				left: initial;
				animation-delay: 0.8s;
				animation-duration: 2.5s;
			}

			span:nth-child(6) {
				top: 0px;
				right: 600px;
				left: initial;
				animation-delay: 1s;
				animation-duration: 3s;
			}

			span:nth-child(7) {
				top: 300px;
				right: 0px;
				left: initial;
				animation-delay: 1.2s;
				animation-duration: 1.75s;
			}

			span:nth-child(8) {
				top: 0px;
				right: 700px;
				left: initial;
				animation-delay: 1.4s;
				animation-duration: 1.25s;
			}

			span:nth-child(9) {
				top: 0px;
				right: 1000px;
				left: initial;
				animation-delay: 0.75s;
				animation-duration: 2.25s;
			}

			span:nth-child(10) {
				top: 0px;
				right: 450px;
				left: initial;
				animation-delay: 2.75s;
				animation-duration: 2.25s;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<!--10个span-->
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
		</div>
	</body>
</html>

http://www.niftyadmin.cn/n/5890834.html

相关文章

AI绘画软件Stable Diffusion详解教程(10):图生图进阶篇(局部手绘修正)

前面两篇的手绘修正和局部替换&#xff0c;手绘修正虽然对局部按涂鸦颜色重绘、但是会把整个图片也都重绘&#xff0c;局部替换虽然只重绘了涂绘的区域&#xff0c;但是都是随机的&#xff0c;没法实现按自己涂鸦的颜色去生成。本篇的局部手绘修正&#xff0c;是前两篇功能的结…

Spring WebSocket 像写http接口一样处理WebSocket消息(Stomp协议)

简单的WebSocket服务搭建 在聊Stomp协议之前&#xff0c;先看一下Spring boot使用比较原始的方法是怎么搭建WebSocket服务的 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactI…

布谷直播系统源码开发实战:从架构设计到性能优化

作为山东布谷科技的一名技术研发人员&#xff0c;我参与了多个直播系统平台从0到1的开发和搭建&#xff0c;也见证了直播行业从萌芽到爆发的全过程。今天&#xff0c;我想从研发角度&#xff0c;分享一些直播系统软件开发的经验和心得&#xff0c;希望能对大家有所帮助。 一、 …

Mmybatis xml 连接数据库的方法

1. 添加依赖&#xff08;Maven项目&#xff09; 在 pom.xml 中添加 MyBatis 和数据库驱动的依赖&#xff08;以 MySQL 为例&#xff09;&#xff1a; <dependencies><!-- MyBatis 核心库 --><dependency><groupId>org.mybatis</groupId><ar…

系统思考:销售业绩与团队士气

“问题的根本不在于结果&#xff0c;而在于原因。” — 彼得德鲁克 最近在和一个华东区域的业务团队沟通长期陪跑项目。表面上看&#xff0c;问题是区域业绩未达标&#xff0c;团队信任和执行力不足。但从更深层次来看&#xff0c;销售业绩下滑并非单一因素造成&#xff0c;而…

【vllm】Qwen2.5-VL-72B-AWQ 部署记录

版本&#xff1a;0.7.2 注意事项&#xff1a; export LD_LIBRARY_PATH/home/xxxxx/anaconda3/envs/xxxxx/lib/python3.10/site-packages/nvidia/nvjitlink/lib:$LD_LIBRARY_PATH # 如果报错可能需要Also pip install --force-reinstall githttps://github.com/huggingface/tra…

Hive高级SQL技巧及实际应用场景

Hive高级SQL技巧及实际应用场景 引言 Apache Hive 是一个建立在Hadoop之上的数据仓库基础设施&#xff0c;它提供了一个用于查询和管理分布式存储中的大型数据集的机制。通过使用类似于SQL&#xff08;称为HiveQL&#xff09;的语言&#xff0c;Hive使得数据分析变得更加简单…

一维数组的增删改查:对元素的影响

一维数组的增删改查:对元素的影响(C语言) 在C语言中,一维数组是一种存储一组相同类型元素的数据结构。它在内存中是连续存储的,每个元素都可以通过索引来访问和修改。在这篇博文中,我们将详细探讨一维数组的增、删、改、查操作,并分析它们对数组元素的影响。 1. 一维数…