进度条与自定义背景多色css/jquery

Mr.*_*per 4 html css jquery html5 progress-bar

我的目标是实现自定义背景的进度条.最后的结果应该看看这个:

在此输入图像描述

背景是(按顺序)绿色,黄色和红色.它在背景上的浅蓝色......进度线.

有一些教程可以做到这一点吗?我已经意识到一些进度条,但我没有自定义背景.谢谢.

Tem*_*fif 6

只需使用线性渐变,您可以根据需要指定任意数量的颜色,并轻松控制每个颜色的百分比:

.progress {
 height:52px;
 width:500px;
 border:2px solid #000;
 text-align:center;
 color:#fff;
 font-size:20px;
 background:linear-gradient(to right, red 20%, blue 20%, blue 50%,yellow 50%,yellow 60% ,green 0);
}
Run Code Online (Sandbox Code Playgroud)
<div class="progress"> 50 %</div>
Run Code Online (Sandbox Code Playgroud)

您还可以考虑使用多个渐变,您可以使用jQuery轻松管理它们background-size:

$('.progress').css('background-size','4% 100%,50% 100% ,60% 100% ,100% 100% ');
setTimeout(function() {
  $('.progress').html('60%')
  $('.progress').css('background-size','20% 100%,30% 100% ,90% 100% ,100% 100% ');
},2000);
Run Code Online (Sandbox Code Playgroud)
.progress {
 height:52px;
 width:500px;
 border:2px solid #000;
 text-align:center;
 color:#fff;
 font-size:20px;
 background-image:
   linear-gradient(red,red),
   linear-gradient(blue,blue),
   linear-gradient(green,green),
   linear-gradient(yellow,yellow);
 background-repeat:no-repeat;
 transition:1s;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Wait to see the animation !
<div class="progress"> 50 %</div>
Run Code Online (Sandbox Code Playgroud)


Meh*_*han 5

下面是使用渐变的示例代码。

/* PROGRESS */
.progress {
  background-color: #e5e9eb;
  height: 1em;
  position: relative;
  width: 34em;
}
.progress-bar {
  animation-duration: 3s;
  animation-name: width;
  background-image: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #34aadc, #5856d6, #ff2d55);
  background-size: 24em 0.25em;
  height: 100%;
  position: relative;
}
@keyframes width {
  0%, 100% {
    transition-timing-function: cubic-bezier(1, 0, 0.65, 0.85);
  }
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
Run Code Online (Sandbox Code Playgroud)
  <h1 class="text-center">Progress Bar</h1>

  <div class="progress">

    <div class="progress-bar">

      <div class="progress-shadow"></div>

    </div>

  </div>
Run Code Online (Sandbox Code Playgroud)