技术频道导航
HTML/CSS
.NET技术
IIS技术
PHP技术
Js/JQuery
Photoshop
Fireworks
服务器技术
操作系统
网站运营
卡卡网是专业的网站测速平台,网速测试,测试网站速度,就来卡卡网 ~
问题反馈网络日志

【DiyVM】沙田机房/香港云/回国CN2线路/AMD EPYC/39元一月5M/CN2海外云主机 24元/月BGP+CN2海外云 低至25元/月海外主机 低至$2/月

DiyVM:香港VPS惊爆价36元一月
★站长变现★特色悬浮小图标广告
5M CN2 GIA云主机 24元起
【转化好产品,官方高价收量】
一一一云主机 26元起一一一
官方高价收量,每日稳定结算

一一云主机 24元 3折起一一
AWS核心代理U充值 免注册开户
海外CN2云 低至$2.5/月
海外云低至2折 298/年
免费测试★APK免杀 谷歌过保护
官方收量CPA/CPS长期稳定

海外主机 5M CN2 低至$2/月
恒创科技 一 海外服务器 ● 高速稳定
★解决安装报毒★谷歌过保护机制
CN2 GIA/1000Mbps $111/月
超级签★免杀★加固★满意付款
全球云主机 3天试用再买

【菠萝云】香港4G内存99元,马上开通
亿人互联-津/京BGP托管租用/VPS
苹果签名/APP封装/远控免杀
10M CN2海外云VPS 53元/月
一一站长/主播好变现一一有流量就来
站长变现 特色悬浮小图标广告

实力产品变现
实力产品变现
实力产品变现
实力产品变现
实力产品变现
实力产品变现

赞助商

分类目录

赞助商

最新文章

字体单位是相对测量单位,是根据其他一些值计算的,可以动态变化。与字体相关的测量单...
stroke-width设置形状的描边粗细,如果在 HTML 中,框架是从外边缘...
本文给大家介绍10款用SVG蒙版制作的图片转场/过渡动画,并分析如何实现它们。
CSS 数据类型<filter-function>代表可以改变输入图...
CSS box-shadow 属性用于在元素的框架上添加阴影效果。你可以在同一个...
drop-shadow() 是一个CSS 过滤器函数,其将投影效果应用于输入图像...
本文给大家介绍一个SVG实现的网页气泡动画效果。 

搜索

CSS实现的下载进程动画【演示/源码】

作者:admin    时间:2023-3-13 17:39:55    浏览:498

在文件下载时,如果能显示一个下载进程,那么对用户来说是一个很好的反馈,本文将给大家介绍一个CSS实现的下载进程动画。

 CSS实现的下载进程动画

demodownload

实例介绍

点击下载按钮后,画圆一周,圆内显示“100%”和一个勾,表示下载进程已经结束。

HTML代码

  1. <button class="button">
  2.     <svg class="circle" viewBox="0 0 76 76">
  3.         <circle class="default" cx="38" cy="38" r="36"></circle>
  4.         <circle class="active" cx="38" cy="38" r="36"></circle>
  5.     </svg>
  6.     <div class="icon">
  7.         <svg class="line" viewBox="0 0 4 37">
  8.             <line x1="2" y1="2" x2="2" y2="35"></line>
  9.         </svg>
  10.         <div>
  11.             <svg class="arrow" viewBox="0 0 40 32"></svg>
  12.             <svg class="progress" viewBox="0 0 444 10">
  13.                 <path d="M2,5 L42,5 C60.0089086,6.33131695..."></path>
  14.             </svg>
  15.         </div>
  16.     </div>
  17.     <span>0%</span>
  18. </button>

HTML结构外部为一个button标签,内部为一个SVG标签、一个div标签和一个span标签,其中SVG是一个圆,它的class值为circle,而div是圆内部的图标,它的class值为iconspan标签显示下载进程的百分比数字。

x

CSS代码

由于涉及元素较多,所以CSS代码也比较多。

.button设置按钮样式。

.circle设置圆的样式。

.button span设置下载进程百分比数字样式。

.icon设置圆容器的样式,.icon svg.line是线条动画的样式。

部分CSS代码:

  1. .button {
  2.   --default: rgba(255, 255, 255, .2);
  3.   --active: #fff;
  4.   position: relative;
  5.   border: none;
  6.   outline: none;
  7.   background: none;
  8.   padding: 0;
  9.   -webkit-appearance: none;
  10.   -webkit-tap-highlight-color: transparent;
  11.   cursor: pointer;
  12.   transform: scale(var(--s, 1));
  13.   transition: transform 0.2s;
  14. }
  15. .button:active {
  16.   --s: .96;
  17. }
  18. .button svg {
  19.   display: block;
  20.   fill: none;
  21.   stroke-width: var(--sw, 3px);
  22.   stroke-linecap: round;
  23.   stroke-linejoin: round;
  24. }
  25. .button .circle {
  26.   width: 76px;
  27.   height: 76px;
  28.   transform: rotate(-90deg);
  29. }
  30. .button .circle circle.default {
  31.   stroke: var(--default);
  32. }
  33. .button .circle circle.active {
  34.   stroke: var(--active);
  35.   stroke-dasharray: 227px;
  36.   stroke-dashoffset: var(--active-offset, 227px);
  37.   transition: stroke-dashoffset var(--all-transition, 4s) ease var(--all-delay, 0.8s);
  38. }
  39. .button span {
  40.   display: block;
  41.   position: absolute;
  42.   left: 0;
  43.   right: 0;
  44.   text-align: center;
  45.   bottom: 13px;
  46.   font-weight: 500;
  47.   font-size: 10px;
  48.   color: var(--active);
  49.   opacity: var(--count-opacity, 0);
  50.   transform: translateY(var(--count-y, 4px));
  51.   -webkit-animation: var(--count, none) 0.3s ease forwards var(--all-delay, 4.6s);
  52.           animation: var(--count, none) 0.3s ease forwards var(--all-delay, 4.6s);
  53.   transition: opacity 0.2s ease 0.6s, transform 0.3s ease 0.6s;
  54. }
  55. .button .icon {
  56.   --sw: 2px;
  57.   width: 24px;
  58.   height: 40px;
  59.   position: absolute;
  60.   left: 50%;
  61.   top: 50%;
  62.   margin: -20px 0 0 -12px;
  63. }
  64. .button .icon svg.line {
  65.   width: 4px;
  66.   height: 37px;
  67.   stroke: var(--active);
  68.   position: absolute;
  69.   left: 10px;
  70.   top: 0;
  71.   stroke-dasharray: 0 33px var(--line-array, 33px) 66px;
  72.   stroke-dashoffset: var(--line-offset, 33px);
  73.   transform: translateY(var(--line-y, 0));
  74.   opacity: var(--line-opacity, 1);
  75.   transition: stroke-dasharray 0.2s, stroke-dashoffset 0.2s, transform 0.32s ease var(--all-delay, 0.25s);
  76. }

此外,还有箭头样式,其CSS代码为:

  1. .button .icon div svg.arrow {
  2.   width: 40px;
  3.   height: 32px;
  4.   opacity: var(--arrow-opacity, 1);
  5.   transition: opacity 0s linear var(--all-delay, 1s);
  6. }

JavaScript代码

本实例动画用SVG完成,所以用到了一个第三方JS库文件gsap.min.js,它的作用是实现SVG动画。

  1. <script src='gsap.min.js'></script>

部分JavaScript代码:

  1. const $ = (s, o = document) => o.querySelector(s);
  2. const $$ = (s, o = document) => o.querySelectorAll(s);
  3.  
  4. $$('.button').forEach(button => {
  5.  
  6.   let count = {
  7.     number: 0 },
  8.  
  9.   icon = $('.icon', button),
  10.   iconDiv = $('.icon > div', button),
  11.   arrow = $('.icon .arrow', button),
  12.   countElem = $('span', button),
  13.   svgPath = new Proxy({
  14.     y: null,
  15.     s: null,
  16.     f: null,
  17.     l: null },
  18.   {
  19.     set(target, key, value) {
  20.       target[key] = value;
  21.       if (target.!== null && target.!= null && target.!= null && target.!= null) {
  22.         arrow.innerHTML = getPath(target.y, target.f, target.l, target.s, null);
  23.       }
  24.       return true;
  25.     },
  26.     get(target, key) {
  27.       return target[key];
  28.     } });
  29.  
  30.  
  31.   svgPath.= 30;
  32.   svgPath.= 0;
  33.   svgPath.= 8;
  34.   svgPath.= 32;
  35.  
  36.   button.addEventListener('click', e => {
  37.     if (!button.classList.contains('loading')) {
  38.  
  39.       if (!button.classList.contains('animation')) {
  40.  
  41.         button.classList.add('loading', 'animation');
  42.  
  43.         gsap.to(svgPath, {
  44.           f: 2,
  45.           l: 38,
  46.           duration: .3,
  47.           delay: .15 });
  48.  
  49.  
  50.         gsap.to(svgPath, {
  51.           s: .2,
  52.           y: 16,
  53.           duration: .8,
  54.           delay: .15,
  55.           ease: Elastic.easeOut.config(1, .4) });
  56.  
  57.  
  58.         gsap.to(count, {
  59.           number: '100',
  60.           duration: 3.8,
  61.           delay: .8,
  62.           onUpdate() {
  63.             countElem.innerHTML = Math.round(count.number) + '%';
  64.           } });
  65.  
  66.  
  67.         setTimeout(() => {
  68.           iconDiv.style.setProperty('overflow', 'visible');
  69.           setTimeout(() => {
  70.             button.classList.remove('animation');
  71.           }, 600);
  72.         }, 4820);
  73.  
  74.       }
  75.  
  76.     } else {
  77.  
  78.       if (!button.classList.contains('animation')) {
  79.  
  80.         button.classList.add('reset');
  81.  
  82.         gsap.to(svgPath, {
  83.           f: 8,
  84.           l: 32,
  85.           duration: .4 });
  86.  
  87.  
  88.         gsap.to(svgPath, {
  89.           s: 0,
  90.           y: 30,
  91.           duration: .4 });
  92.  
  93.  
  94.         setTimeout(() => {
  95.           button.classList.remove('loading', 'reset');
  96.           iconDiv.removeAttribute('style');
  97.         }, 400);
  98.  
  99.       }
  100.  
  101.     }
  102.     e.preventDefault();
  103.   });
  104.  
  105. });

总结

本文介绍了一个CSS实现的下载进程动画,这个动画对用户来说是一个很好的等待反馈,喜欢的朋友可以下载源码直接使用。

相关文章

标签: css  animation  动画  下载进程动画  
x
广告: CN2云主机 免费试用