网页动画气泡效果

21 篇文章 0 订阅
13 篇文章 0 订阅

打开网页,从网页底部生成一个一个的气泡,然后气泡上升到页面顶部消失。

利用  setinterval定时器定时,每50毫秒生成一个气泡,然后设置他的样式,出现效果

效果图:

页面布局代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网页动画气泡效果</title>
		<link rel="stylesheet" type="text/css" href="../lib/css/qipao.css"/>
	</head>
	<body>
		<section>
			<h2>hello world</h2>
		</section>
	</body>
	<script type="text/javascript">
		function createBubble() {
			const section = document.querySelector('section')
			const createElement = document.createElement('span')
			var size = Math.random() * 60
			createElement.style.width = 20 + size + 'px'
			createElement.style.height = 20 + size + 'px'
			createElement.style.left = Math.random() * innerWidth + 'px'
			section.appendChild(createElement)
			setTimeout( () => {
				createElement.remove()
			},4000)
		}
		setInterval(createBubble,50)
	</script>
</html>

css代码:

*{
	margin: 0;
	padding: 0;
	font-family: consolas;
}
section{
	position: relative;
	width: 100%;
	height: 100vh;
	overflow: hidden;
	background: #111;
	display: flex;
	justify-content: center;
	align-items: center;
}
section h2{
	font-size: 10em;
	color: #333;
}
section span {
	position: absolute;
	bottom: -50px;
	background: transparent;
	border-radius: 50%;
	pointer-events: none;
	box-shadow: inset 0 0 10px rgba(255,255,255,0.5);
	animation: animate 4s linear infinite;
}
section span:before{
	content: '';
	position: absolute;
	width: 100%;
	height: 100%;
	transform: scale(0.25) translate(-70%,-70%);
	background: radial-gradient(#fff,transparent);
	border-radius: 50%;
	
}
@keyframes animate{
	0%{
		transform: translateY(0%);
		opacity: 1;
	}
	99%{
		opacity: 1;
	}
	100%{
		transform: translateY(-1200%);
		opacity: 0;
	}
}

 

 

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值