返回列表 发布新帖
查看: 2213|回复: 0

[代码特效] HTML&CSS :炫酷的进度条动画

灌水成绩
536
55
1317
主题
回帖
积分

等级头衔
U I D : 1
用户组 : 管理员

积分成就
威望 : 1 点
糖 : 544 个
贡献 : 20178 点
在线时间 : 184 小时
注册时间 : 2025-1-1
最后登录 : 2025-4-17

荣誉勋章

活跃会员热心会员灌水之王博客真神优秀版主荣誉会员论坛元老优秀作者帅哥认证管理员挂机之王管理团队勋章

发表于 2025-3-3 17:59:34 | 查看全部 |阅读模式
这段代码实现了一个具有动态背景、颜色变化和3D阴影的进度条动画。它不仅模拟了加载进度,还通过丰富的视觉效果增强了用户体验。

演示效果



HTML&CSS


  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>老会博客:www.lhbk.cn</title>
  7.     <style>
  8.         body {
  9.             margin: 0;
  10.             padding: 0;
  11.             background: #e8e8e8;
  12.             display: flex;
  13.             align-items: center;
  14.             justify-content: center;
  15.             height: 100vh;
  16.         }

  17.         .progress {
  18.             --progress-color: rgb(184, 20, 255);
  19.             display: flex;
  20.             flex-direction: row;
  21.             align-items: center;
  22.             justify-content: center;
  23.             position: relative;
  24.             z-index: 9999;
  25.             height: 1.25rem;
  26.             width: 200px;
  27.             border-radius: 6px;
  28.             outline: 1.5px solid #6a6a6b;
  29.             border: 2px solid transparent;
  30.             overflow: hidden;
  31.             transition: all 125ms ease;
  32.             animation: outline 4s ease infinite;
  33.             background-color: white;
  34.             box-shadow:
  35.                 inset 0.2rem 0.2rem 0.5rem #b8b8b9,
  36.                 inset -0.2rem -0.2rem 0.5rem #7c7c7c7c;
  37.         }

  38.         .progress::before {
  39.             content: "loading";
  40.             position: absolute;
  41.             font-weight: 600;
  42.             font-size: 14px;
  43.             z-index: 9;
  44.             animation: colors 4s ease infinite;
  45.         }

  46.         .bar {
  47.             position: absolute;
  48.             display: flex;
  49.             align-items: center;
  50.             justify-content: center;
  51.             width: 100%;
  52.             height: 100%;
  53.             transform-origin: left center;
  54.             animation: progress 4s ease infinite;
  55.         }

  56.         .bar::before {
  57.             content: "";
  58.             position: absolute;
  59.             inset: 0;
  60.             height: 100%;
  61.             width: 100%;
  62.             border-radius: 6px;
  63.             transform-origin: left center;
  64.             transition: all 125ms ease;
  65.             background-size: 1.25rem 1.25rem;
  66.             box-shadow:
  67.                 inset 0.3rem 0.3rem 0.6rem #ffffff8f,
  68.                 inset -0.2rem -0.2rem 0.5rem #77777777;
  69.             background-image: linear-gradient(45deg,
  70.                     #cccccc33 25%,
  71.                     transparent 0,
  72.                     transparent 50%,
  73.                     #cccccc33 0,
  74.                     #cccccc33 75%,
  75.                     transparent 0,
  76.                     transparent);
  77.             animation: bar 1s linear infinite;
  78.         }

  79.         .bar::after {
  80.             content: "";
  81.             inset: 0;
  82.             height: 100%;
  83.             width: 100%;
  84.             border-radius: 4px;
  85.             background-color: var(--progress-color);
  86.             background: linear-gradient(90deg, #3f5efb 0%, #fc466b 100%);
  87.         }

  88.         @keyframes outline {
  89.             from {
  90.                 outline-color: #6a6a6b;
  91.             }

  92.             50% {
  93.                 outline-color: #fac826;
  94.             }

  95.             to {
  96.                 outline-color: #fc466b;
  97.             }
  98.         }

  99.         @keyframes colors {
  100.             from {
  101.                 color: #000;
  102.             }

  103.             to {
  104.                 color: #fff;
  105.             }
  106.         }

  107.         @keyframes progress {
  108.             from {
  109.                 transform: translateX(-100%);
  110.             }

  111.             to {
  112.                 transform: translateX(0%);
  113.             }
  114.         }

  115.         @keyframes bar {
  116.             from {
  117.                 background-position: 0 0;
  118.             }

  119.             to {
  120.                 background-position: 2.5rem 0;
  121.             }
  122.         }
  123.     </style>
  124. </head>

  125. <body>
  126.     <div class="progress">
  127.         <div class="bar"></div>
  128.     </div>

  129. </body>
  130. </html>
复制代码


HTML 结构

progress:进度条的容器,包含整个进度条的样式和动画。
bar:进度条的内部元素,用于实现进度条的动态效果。

CSS 样式

body:设置页面背景颜色、布局方式(居中对齐)和全屏高度。
.progress:定义进度条的样式,包括大小、背景颜色、边框、阴影和动画效果。
.progress::before:在进度条上显示“loading”文本,并通过colors动画实现颜色变化效果。
.bar:定义进度条内部的动画效果,通过progress动画实现水平移动。
.bar::before:为进度条添加渐变背景和动态阴影效果,通过bar动画实现背景的滚动效果。
.bar::after:为进度条添加渐变背景颜色,从蓝色到红色的渐变。
@keyframes outline:定义进度条边框的颜色变化动画。
@keyframes colors:定义“loading”文本的颜色变化动画。
@keyframes progress:定义进度条的水平移动动画。
@keyframes bar:定义进度条背景的滚动动画。


本帖子中包含更多资源

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

×
老会博客欢迎您
回复

使用道具 举报

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

本版积分规则

投诉/建议联系

10231020@qq.com

老会博客(www.lhbk.cn)专注网络技术分享,
主要分享技术教程程序源码,网络技术,PSD源码,
模板插件,活动分享,各类教程,绿色软件,QQ资源,
致力创造一个高质量分享平台
  • 添加微信客服
  • 加入官方QQ群
Copyright © 2001-2025 老会博客 版权所有 All Rights Reserved.
关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表