CSS 3.0实现泡泡特效

给大家分享一个用CSS 3.0实现的泡泡特效,效果如下:

 以下是代码实现,欢迎大家复制、粘贴和收藏。

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>CSS 3.0实现泡泡特效</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. section {
  13. position: relative;
  14. width: 100%;
  15. height: 100vh;
  16. overflow: hidden;
  17. background: #111;
  18. display: flex;
  19. align-items: center;
  20. justify-content: center;
  21. }
  22. section h2 {
  23. font-size: 10em;
  24. color: #333;
  25. }
  26. section span {
  27. position: absolute;
  28. bottom: -50px;
  29. background: transparent;
  30. border-radius: 50%;
  31. pointer-events: none;
  32. box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
  33. animation: animate 4s linear infinite;
  34. }
  35. section span::before {
  36. content: '';
  37. position: absolute;
  38. width: 100%;
  39. height: 100%;
  40. transform: scale(0.25) translate(-70%, -70%);
  41. background: radial-gradient(#fff, transparent);
  42. border-radius: 50%;
  43. }
  44. @keyframes animate {
  45. 0% {
  46. transform: translateY(0%);
  47. opacity: 1;
  48. }
  49. 99% {
  50. opacity: 1;
  51. }
  52. 100% {
  53. transform: translateY(-1200%);
  54. opacity: 0;
  55. }
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <section>
  61. <h2>Bubbles</h2>
  62. </section>
  63. <script>
  64. function createBubble() {
  65. const section = document.querySelector('section')
  66. const createElement = document.createElement('span')
  67. let size = Math.random() * 60
  68. createElement.style.width = 20 + size + 'px'
  69. createElement.style.height = 20 + size + 'px'
  70. createElement.style.left = Math.random() * innerWidth + 'px'
  71. section.append(createElement)
  72. setTimeout(() => {
  73. createElement.remove()
  74. }, 4000)
  75. }
  76. setInterval(createBubble, 50)
  77. </script>
  78. </body>
  79. </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值