火箭飞行动画效果实现

使用css动画实现火箭飞行的动画

页面布局代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>火箭飞行动画</title>
		<link rel="stylesheet" type="text/css" href="../lib/css/rocket.css"/>
	</head>
	<body>
		<div class="scene">
			<div class="rocket">
				<img src="../lib/image/rocket.jpg" >
			</div>
		</div>
	</body>
	<script type="text/javascript">
		function stars(){
			let count = 50;
			let scene = document.querySelector('.scene');
			let i = 0;
			while(i < count){
				let star = document.createElement('i');
				let x = Math.floor(Math.random() * window.innerWidth);
				let duration = Math.random() * 1;
				let h = Math.random() * 100;
				star.style.left = x + 'px';
				star.style.width = 1 + 'px';
				star.style.height = h + 'px';
				star.style.animationDuration = duration + 's';
				scene.appendChild(star);
				i++;
			}
		}
		stars();
	</script>
</html>

 

css代码

*{
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
.scene{
	position: relative;
	width: 100%;
	height: 100vh;
	background: #01070a;
	overflow: hidden;
	display: flex;
	justify-content: center;
	align-items: center;
}
.scene i {
	position: absolute;
	top: -250px;
	background: rgba(255,255,255,0.5);
	animation: animateStars linear infinite;
}
@keyframes animateStars{
	0%{
		transform: translateY(0);
	}
	100%{
		transform: translateY(200vh);
	}
}
.scene .rocket{
	position: relative;
	animation: animate 0.2s ease infinite;
}
@keyframes animate{
	0%{
		transform: translateY(-2px);
	}
	50%{
		transform: translateY(2px);
	}
}
.scene .rocket::before{
	content: '';
	position: absolute;
	bottom: -150px;
	left: 50%;
	transform: translateX(-50%);
	width: 10px;
	height: 150px;
	background: linear-gradient(#00d0ff,transparent);
	/* filter: blur(20px); */
}
.scene .rocket::after{
	content: '';
	position: absolute;
	bottom: -200px;
	left: 50%;
	transform: translateX(-50%);
	width: 10px;
	height: 200px;
	background: linear-gradient(#00d0ff,transparent);
	filter: blur(20px);
}

 

火箭图片

 

效果图

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值