鱼C论坛

 找回密码
 立即注册
查看: 2296|回复: 4

[作品展示] 【HTML】落雪特效

[复制链接]
发表于 2022-1-24 21:48:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 ckblt 于 2022-1-25 19:38 编辑

我做了个落雪特效,分享给大家。
Github:加速的github链接或者默认的github链接

  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="UTF-8" />
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7.     <title>Snow</title>

  8.     <style>
  9.       * {
  10.         margin: 0;
  11.         padding: 0;
  12.       }

  13.       body {
  14.         max-width: 100vw;
  15.         max-height: 100vh;
  16.         overflow: hidden;
  17.         background-color: #4b495a;
  18.       }

  19.       .snow {
  20.         position: absolute;
  21.         width: var(--size);
  22.         height: var(--size);
  23.         top: var(--top);
  24.         left: var(--left);
  25.         border-radius: 50%;
  26.         opacity: 0.7;
  27.         background-color: #bfc8d6;
  28.         filter: blur(calc(var(--size) / 5));
  29.       }
  30.       #text {
  31.         display: flex;
  32.         justify-content: center;
  33.         align-items: center;
  34.         flex-direction: column;
  35.         min-height: 100vh;
  36.         color: #9ca2ac;
  37.       }
  38.       #text h1 {
  39.         font-size: 200px;
  40.         filter: blur(5px);
  41.       }
  42.       #text p {
  43.         font-size: 30px;
  44.         filter: blur(1.5px);
  45.       }
  46.     </style>
  47.   </head>
  48.   <body>
  49.     <div id="text">
  50.       <h1>SNOW</h1>
  51.       <p>Simple snow effect.</p>
  52.     </div>

  53.     <script>
  54.       function random(x, y) {
  55.         return Math.random() * (x - y) + y;
  56.       }
  57.       setInterval(() => {
  58.         const snow = document.createElement('div');
  59.         let t = 0;
  60.         let speed = random(3, 5);
  61.         let l = random(0, window.innerWidth + 100);
  62.         snow.style.setProperty('--size', `${random(5, 20)}px`);
  63.         snow.style.setProperty('--top', `${t}px`);
  64.         snow.style.setProperty('--left', `${l}px`);
  65.         snow.classList.add('snow');
  66.         setInterval(() => {
  67.           if (t > window.innerHeight || l < 0) {
  68.             snow.remove();
  69.           }
  70.           snow.style.setProperty('--top', `${t}px`);
  71.           snow.style.setProperty('--left', `${l}px`);
  72.           l += -0.5;
  73.           t += speed;
  74.         }, 1000 / 60);
  75.         document.body.append(snow);
  76.       }, 1000 / 30);
  77.     </script>
  78.   </body>
  79. </html>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-1-25 08:49:11 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-2-16 11:02:42 | 显示全部楼层
运行起来效果是相当浪漫!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-17 10:08:50 From FishC Mobile | 显示全部楼层
厉害了呀,大佬。666
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-18 10:07:47 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-2 00:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表