进度条设计详解

一、进度条的基本概念

进度条是指在程序执行中,用一个矩形或线条表示程序进程的一种控件。主要用于提示用户当前正在执行的任务的进程和状态,以及预计完成时间。

进度条由填充、边框和背景组成。进度条的长度代表任务完成量的百分比。在进度条上,还会显示任务的名称、剩余时间和完成百分比等信息。

二、进度条的种类

常见的进度条分为水平进度条和垂直进度条,另外还有圆形进度条。

三、水平进度条的设计

1、基本样式的HTML代码如下所示:

<div class="progress-bar">
  <div class="progress">
    <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="75" 
    aria-valuemin="0" aria-valuemax="100" style="width: 75%;">
    </div>
  </div>
</div>

2、CSS样式代码如下所示:

.progress-bar {
  height: 25px;
  background-color: #f5f5f5;
  border-radius: 5px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
  margin-top: 10px;
  margin-bottom: 10px;
}

.progress {
  height: 25px;
  margin-bottom: 10px;
  overflow: hidden;
  background-color: #ddd;
  border-radius: 5px;
}

.progress-bar-striped {
  -webkit-animation: progress-bar-stripes 2s linear infinite;
  animation: progress-bar-stripes 2s linear infinite;
}
@-webkit-keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {
    background-position: 0 0;
  }
}
@keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {
    background-position: 0 0;
  }
}

3、JavaScript代码如下所示:

function progress(percent, $element) {
  var progressBarWidth = percent * $element.width() / 100;
  $element.find('.progress-bar').animate({ width: progressBarWidth }, 500);
}

progress(50, $('.progress'));

四、垂直进度条的设计

1、基本样式的HTML代码如下所示:

<div class="progress progress-vertical">
  <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40"
  aria-valuemin="0" aria-valuemax="100" style="height: 40%;">
    <span class="sr-only">40% Complete (success)</span>
  </div>
</div>

2、CSS样式代码如下所示:

.progress-vertical {
  width: 20px;
  height: 200px;
  margin-left: 50px;
  margin-top: 50px;
  margin-bottom: 50px;
  transform: rotate(-90deg);
}

.progress-bar {
  width: 100%;
  background-color: #428bca;
}

3、JavaScript代码如下所示:

function progress(percent, $element) {
  var progressBarHeight = percent * $element.height() / 100;
  $element.find('.progress-bar').animate({ height: progressBarHeight }, 500);
}

progress(50, $('.progress-vertical'));

五、圆形进度条的设计

1、基本样式的HTML代码如下所示:

<div class="circular-progress-bar">
  <div class="background"></div>
  <div class="circle">
    <div class="mask full">
      <div class="fill"></div>
    </div>
    <div class="mask half">
      <div class="fill"></div>
      <div class="fill fix"></div>
    </div>
    <div class="shadow"></div>
  </div>
</div>

2、CSS样式代码如下所示:

.circular-progress-bar {
  width: 100px;
  height: 100px;
  position: relative;
  margin: 0 auto;
}

.background {
  width: 100%;
  height: 100%;
  border-radius: 50px;
  background-color: #f2f2f2;
}

.circle {
  width: 100%;
  height: 100%;
  clip: rect(0, 100px, 100px, 50px);
  position: absolute;
}

.mask {
  width: 100%;
  height: 100%;
  clip: rect(0, 50px, 100px, 0);
  position: absolute;
}

.fill {
  width: 100%;
  height: 100%;
  border-radius: 50px;
  background-color: #428bca;
}

.half .fill.fix {
  position: absolute;
  top: 0;
  right: 0;
  width: 50px;
  height: 100%;
  clip: rect(0, 50px, 100px, 0);
}

.shadow {
  width: 100%;
  height: 100%;
  border-radius: 50px;
  box-shadow: 0px 0px 0px 3px #f2f2f2 inset;
}

3、JavaScript代码如下所示:

function progress(percent, $element) {
  var degrees = percent / 100 * 360;
  $element.find('.fill').css({ 'transform': 'rotate(' + degrees + 'deg)' });
}

progress(50, $('.circular-progress-bar'));

六、总结

在设计进度条时,需要考虑任务的复杂程度、数据的更新速度、用户的操作体验等多个因素。良好的进度条设计可以提升用户的体验感,让用户更好地理解任务的执行进程和状态。

原创文章,作者:XZQHM,如若转载,请注明出处:https://www.506064.com/n/370598.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
XZQHMXZQHM
上一篇 2025-04-22 01:14
下一篇 2025-04-22 01:14

相关推荐

  • Linux sync详解

    一、sync概述 sync是Linux中一个非常重要的命令,它可以将文件系统缓存中的内容,强制写入磁盘中。在执行sync之前,所有的文件系统更新将不会立即写入磁盘,而是先缓存在内存…

    编程 2025-04-25
  • 神经网络代码详解

    神经网络作为一种人工智能技术,被广泛应用于语音识别、图像识别、自然语言处理等领域。而神经网络的模型编写,离不开代码。本文将从多个方面详细阐述神经网络模型编写的代码技术。 一、神经网…

    编程 2025-04-25
  • git config user.name的详解

    一、为什么要使用git config user.name? git是一个非常流行的分布式版本控制系统,很多程序员都会用到它。在使用git commit提交代码时,需要记录commi…

    编程 2025-04-25
  • nginx与apache应用开发详解

    一、概述 nginx和apache都是常见的web服务器。nginx是一个高性能的反向代理web服务器,将负载均衡和缓存集成在了一起,可以动静分离。apache是一个可扩展的web…

    编程 2025-04-25
  • MPU6050工作原理详解

    一、什么是MPU6050 MPU6050是一种六轴惯性传感器,能够同时测量加速度和角速度。它由三个传感器组成:一个三轴加速度计和一个三轴陀螺仪。这个组合提供了非常精细的姿态解算,其…

    编程 2025-04-25
  • Python输入输出详解

    一、文件读写 Python中文件的读写操作是必不可少的基本技能之一。读写文件分别使用open()函数中的’r’和’w’参数,读取文件…

    编程 2025-04-25
  • Linux修改文件名命令详解

    在Linux系统中,修改文件名是一个很常见的操作。Linux提供了多种方式来修改文件名,这篇文章将介绍Linux修改文件名的详细操作。 一、mv命令 mv命令是Linux下的常用命…

    编程 2025-04-25
  • 详解eclipse设置

    一、安装与基础设置 1、下载eclipse并进行安装。 2、打开eclipse,选择对应的工作空间路径。 File -> Switch Workspace -> [选择…

    编程 2025-04-25
  • Python安装OS库详解

    一、OS简介 OS库是Python标准库的一部分,它提供了跨平台的操作系统功能,使得Python可以进行文件操作、进程管理、环境变量读取等系统级操作。 OS库中包含了大量的文件和目…

    编程 2025-04-25
  • Java BigDecimal 精度详解

    一、基础概念 Java BigDecimal 是一个用于高精度计算的类。普通的 double 或 float 类型只能精确表示有限的数字,而对于需要高精度计算的场景,BigDeci…

    编程 2025-04-25

发表回复

登录后才能评论