虚位以待,此位置招租
虚位以待,此位置招租
虚位以待,此位置招租
虚位以待,此位置招租
虚位以待,此位置招租
虚位以待,此位置招租
DeepSook聚合登录 阿里云服务器 99元/年 大流量卡 - 免开卡,免运费 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租
输入验证码,即可复制
扫描二维码输入:jiuge,即可获取验证码
只需要3秒时间
返回列表 发布新帖

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

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

演示效果
640.gif

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>公众号关注:前端Hardy</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:定义进度条背景的滚动动画。

免责声明

本社区仅提供信息交流平台,帖子内容由用户自行发布,不代表社区立场。用户对发布内容负全责,包括版权、隐私、诽谤等,社区不承担因使用社区内容导致的损失。禁止发布侵权、隐私信息,发现侵权请联系我们。社区不负责第三方内容,用户因访问第三方内容产生的损失,社区不担责。用户须遵守规则和法律,不得发布违法、不当内容,违规内容将被删除。发表帖子即同意本声明,不同意请勿发帖。


特别提醒:网络空间并非法外之地,请广大用户自觉遵守法律法规,共同营造健康、文明、有序的网络环境。

本社区运营团队

联系我们: 如有疑问或发现违规行为,请联系管理员:kefu@foxccs.com

远方路灯明灭,银河倾斜,一斛星斗洒满天街。

回复

快捷回复: 经历想经历的,成为想成为的 - 九歌社区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

投诉/建议联系

foxccs@qq.com

网站内容来源于网络,版权争议与本站无关。
请在下载后的24小时内从您的设备中彻底删除上述内容。

  • QQ交流群
  • 添加微信客服
Copyright © 2004-2025 九歌社区 版权所有 All Rights Reserved.
关灯 在本版发帖
扫一扫添加微信客服
官方QQ交流群
手机扫一扫访问
返回顶部
快速回复 返回顶部 返回列表