CSS/JS泡泡飘动特效是一种通过CSS动画和JavaScript控制实现的视觉效果,通常用于网页或应用中增加动态元素,提升用户体验。这种特效模拟了泡泡从页面底部升起并在空中飘动的自然现象。
以下是一个简单的CSS/JS泡泡飘动特效的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>泡泡飘动特效</title>
<style>
.bubble {
position: absolute;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.5);
bottom: 0;
animation: rise 5s linear infinite;
}
@keyframes rise {
0% { transform: translateY(0); }
100% { transform: translateY(-100vh); }
}
</style>
</head>
<body>
<div class="bubble" style="width: 50px; height: 50px;"></div>
<div class="bubble" style="width: 30px; height: 30px; left: 50%;"></div>
<script>
function createBubble() {
const bubble = document.createElement('div');
bubble.classList.add('bubble');
bubble.style.width = `${Math.random() * 50 + 20}px`;
bubble.style.height = bubble.style.width;
bubble.style.left = `${Math.random() * 100}vw`;
document.body.appendChild(bubble);
setTimeout(() => bubble.remove(), 5000);
}
setInterval(createBubble, 1000);
</script>
</body>
</html>
通过以上方法,你可以实现一个简单而有趣的CSS/JS泡泡飘动特效,提升网页的视觉效果和用户体验。
领取专属 10元无门槛券
手把手带您无忧上云