我的目标是实现与自定义背景的进度条。最终的结果应该是看看这个:
背景是(按顺序)绿色,黄色和红色。该lightblue颜色是在背景...进度线。
有一些教程,使这个?我已经悟出了一些进度条,但没有与自定义背景,我会。谢谢。
只需使用线性渐变和你愿意,你可以指定尽可能多的颜色,轻松地控制每一个的%:
.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);
}
<div class="progress"> 50 %</div>
你也可以考虑多梯度和您可以将它们使用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);
.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;
}
<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>
下面使用渐变色样本code.I已经尝试
/* 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%;
}
}
<h1 class="text-center">Progress Bar</h1>
<div class="progress">
<div class="progress-bar">
<div class="progress-shadow"></div>
</div>
</div>
您可以创建将多个酒吧与类.progress同一div堆叠进度条如本w3schools example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Stacked Progress Bars</h2>
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" style="width:40%">
Free Space
</div>
<div class="progress-bar progress-bar-warning" role="progressbar" style="width:10%">
Warning
</div>
<div class="progress-bar progress-bar-danger" role="progressbar" style="width:20%">
Danger
</div>
</div>
</div>
</body>
</html>
如果你愿意在你的项目中使用Bootstrap,只是使用它的Progress bar组件。
即使你不想使用引导程序(或类似的框架),来看看,作为一个例子来建立你的。