让一个小球无限的弹弹弹~(CSS实现球无限弹动)

效果图

在这里插入图片描述

制作步骤

做个球放在网页中央

<style type="text/css">
	*{padding: 0;margin: 0;}
	body{
		width: 100vw;
		height: 100vh;
		background: #b2bec3;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	div.ball{
		position: absolute;
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background: radial-gradient(at center,
			#74b9ff,#0984e3);
	}
</style>
<div class="ball"></div>

这一步完成后效果
在这里插入图片描述

让球跳起来

<style type="text/css">
	*{padding: 0;margin: 0;}
	body{
		width: 100vw;
		height: 100vh;
		background: #b2bec3;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	div.ball{
		position: absolute;
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background: radial-gradient(at center,
			#74b9ff,#0984e3);
		animation:bounce 2s;
		animation-direction: alternate-reverse;
		animation-iteration-count: infinite;
	}
	
	@keyframes bounce{
		to{
			transform: translateY(-300px);
		}
	}
</style>
<div class="ball"></div>

这一步完成后效果
在这里插入图片描述

加个落地阴影

<style type="text/css">
	*{padding: 0;margin: 0;}
	body{
		width: 100vw;
		height: 100vh;
		background: #b2bec3;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	div.ball{
		position: absolute;
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background: radial-gradient(at center,
			#74b9ff,#0984e3);
		animation:bounce 2s;
		animation-direction: alternate-reverse;
		animation-iteration-count: infinite;
	}

	div.shadow{
		position: absolute;
		z-index: -1;
		width: 100px;
		height: 40px;
		border-radius: 50%;
		background: rgba(0,0,0,.5);
		filter: blur(5px);
		transform: translateY(20px);
	}

	@keyframes bounce{
		to{
			transform: translateY(-300px);
		}
	}
</style>
<div class="ball"></div>
<div class="shadow"></div>

加过的效果
在这里插入图片描述

让阴影更加自然(加上动效)

<style type="text/css">
	*{padding: 0;margin: 0;}
	body{
		width: 100vw;
		height: 100vh;
		background: #b2bec3;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	div.ball{
		position: absolute;
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background: radial-gradient(at center,
			#74b9ff,#0984e3);
		animation:bounce 2s;
		animation-direction: alternate-reverse;
		animation-iteration-count: infinite;
	}

	div.shadow{
		position: absolute;
		z-index: -1;
		width: 100px;
		height: 40px;
		border-radius: 50%;
		background: rgba(0,0,0,.5);
		filter: blur(5px);
		transform: translateY(20px);
		animation:shadow 2s;
		animation-direction: alternate-reverse;
		animation-iteration-count: infinite;
	}

	@keyframes bounce{
		to{
			transform: translateY(-300px);
		}
	}

	@keyframes shadow{
		to{
			rgba(0,0,0,.1);
			filter: blur(30px);
		}
	}
</style>
<div class="ball"></div>
<div class="shadow"></div>

最终效果
在这里插入图片描述

完整代码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>无限弹动小球</title>
	<style type="text/css">
		*{padding: 0;margin: 0;}
		body{
			width: 100vw;
			height: 100vh;
			background: #b2bec3;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		div.ball{
			position: absolute;
			width: 50px;
			height: 50px;
			border-radius: 50%;
			background: radial-gradient(at center,
				#74b9ff,#0984e3);
			animation:bounce 2s;
			animation-direction: alternate-reverse;
			animation-iteration-count: infinite;
		}

		div.shadow{
			position: absolute;
			z-index: -1;
			width: 100px;
			height: 40px;
			border-radius: 50%;
			background: rgba(0,0,0,.5);
			filter: blur(5px);
			transform: translateY(20px);
			animation:shadow 2s;
			animation-direction: alternate-reverse;
			animation-iteration-count: infinite;
		}

		@keyframes bounce{
			to{
				transform: translateY(-300px);
			}
		}

		@keyframes shadow{
			to{
				rgba(0,0,0,.1);
				filter: blur(30px);
			}
		}
	</style>
</head>
<body>
	<div class="ball"></div>
	<div class="shadow"></div>
</body>
</html>

本博客其他文章推荐

如果有一屏幕的爱心,你愿意送给谁?(简单实现原生js、css随机生成521个心)

maven新手上路–创建webapp项目,引入jstl、el依赖及el不解析的问题解决(详细图文)

springmvc5.1.9在控制器中一个方法可跳视图也可跳方法问题解决

手撸一个自己的简易struts2框架吧!

struts2.5.20使用通配符和出现的问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值