【问题标题】:How to create bootstrap based steps progress bar?如何创建基于引导的步骤进度条?
【发布时间】:2016-06-07 11:10:18
【问题描述】:

我正在尝试使用带有圆圈的线性进度条来指示用于显示用户进度的步骤,如下图所示:

.

我总共有 7 页。 所以页面将是 1、2、3、4、5、6、6

我制作了 1 个进度条,但它不依赖于页面,我想要一些事情,例如当用户单击页面中的下一个按钮然后它重定向到另一个页面并且进度条显示第 2 步和所有 7 个页面的类似内容

下面是我目前的代码:

$(document).ready(function() {
  var i = 1;
  $('.progress .circle').removeClass().addClass('circle');
  $('.progress .bar').removeClass().addClass('bar');
  setInterval(function() {
    $('.progress .circle:nth-of-type(' + i + ')').addClass('active');

    $('.progress .circle:nth-of-type(' + (i - 1) + ')').removeClass('active').addClass('done');

    $('.progress .circle:nth-of-type(' + (i - 1) + ') .label').html('✓');

    $('.progress .bar:nth-of-type(' + (i - 1) + ')').addClass('active');

    $('.progress .bar:nth-of-type(' + (i - 2) + ')').removeClass('active').addClass('done');

    i++;

    if (i == 0) {
      $('.progress .bar').removeClass().addClass('bar');
      $('.progress div.circle').removeClass().addClass('circle');
      i = 1;
    }
  }, 1000);
});
body {
  font-family: 'Lato', sans-serif;
}
.progress {
  width: 1000px;
  margin: 20px auto;
  text-align: center;
}
.progress .circle,
.progress .bar {
  display: inline-block;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  border: 1px solid #d5d5da;
}
.progress .bar {
  position: relative;
  width: 80px;
  height: 6px;
  top: -33px;
  margin-left: -5px;
  margin-right: -5px;
  border-left: none;
  border-right: none;
  border-radius: 0;
}
.progress .circle .label {
  display: inline-block;
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 32px;
  margin-top: 3px;
  color: #b5b5ba;
  font-size: 17px;
}
.progress .circle .title {
  color: #b5b5ba;
  font-size: 13px;
  line-height: 30px;
  margin-left: -5px;
}
/* Done / Active */

.progress .bar.done,
.progress .circle.done {
  background: #eee;
}
.progress .bar.active {
  background: linear-gradient(to right, #EEE 40%, #FFF 60%);
}
.progress .circle.done .label {
  color: #FFF;
  background: #66cccc;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.done .title {
  color: #444;
}
.progress .circle.active .label {
  color: #FFF;
  background: #0c95be;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.active .title {
  color: #0c95be;
}
.bar.done {
  background: #66cccc !important;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<div class="progress">
  <div class="circle done">
    <span class="label">1</span>
    <span class="title">0%</span>
  </div>
  <span class="bar done"></span>
  <div class="circle done">
    <span class="label">2</span>
    <span class="title">25%</span>
  </div>
  <span class="bar half"></span>
  <div class="circle active">
    <span class="label">3</span>
    <span class="title">50%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">4</span>
    <span class="title">75%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">5</span>
    <span class="title">100%</span>
  </div>
</div>

【问题讨论】:

  • 我添加了我的代码,现在请帮助我
  • @user3784723 既然您要重定向到新页面,为什么不能硬编码每个页面中的圆圈状态?例如第一页的代码总是显示第一个圆圈,第二页总是显示第二个圆圈等等......你甚至可以使用静态图像......这有什么问题?
  • 实际上我想在第二页显示step1和step2之间的一半,我需要css。这可能吗?

标签: javascript jquery html twitter-bootstrap css


【解决方案1】:

您可以通过将当前span.bar 元素拆分为两个大小为一半的元素来显示条的一半。

例如:

.progress .bar-half {
  width: 40px;
}
<span class="bar bar-half done"></span>
<span class="bar bar-half"></span>

然后,您可以通过将类 done 添加到相应的栏中来指示进度。

因此,在您的情况下,您可以简单地在每个 HTML 页面中设置带有静态进度的进度条。

以下是半填充条的示例:

body {
  font-family: 'Lato', sans-serif;
}
.progress {
  width: 1000px;
  margin: 20px auto;
  text-align: center;
}
.progress .circle,
.progress .bar {
  display: inline-block;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  border: 1px solid #d5d5da;
}
.progress .bar {
  position: relative;
  width: 80px;
  height: 6px;
  top: -33px;
  margin-left: -5px;
  margin-right: -5px;
  border-left: none;
  border-right: none;
  border-radius: 0;
}
.progress .bar-half {
  width: 40px;
}
.progress .circle .label {
  display: inline-block;
  width: 32px;
  height: 32px;
  line-height: 32px;
  border-radius: 32px;
  margin-top: 3px;
  color: #b5b5ba;
  font-size: 17px;
}
.progress .circle .title {
  color: #b5b5ba;
  font-size: 13px;
  line-height: 30px;
  margin-left: -5px;
}
/* Done / Active */

.progress .bar.done,
.progress .circle.done {
  background: #eee;
}
.progress .bar.active {
  background: linear-gradient(to right, #EEE 40%, #FFF 60%);
}
.progress .circle.done .label {
  color: #FFF;
  background: #66cccc;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.done .title {
  color: #444;
}
.progress .circle.active .label {
  color: #FFF;
  background: #0c95be;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, .2);
}
.progress .circle.active .title {
  color: #0c95be;
}
.bar.done {
  background: #66cccc !important;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<div class="progress">
  <div class="circle done">
    <span class="label">1</span>
    <span class="title">0%</span>
  </div>
  <span class="bar bar-half done"></span>
  <span class="bar bar-half"></span>
  <div class="circle">
    <span class="label">2</span>
    <span class="title">25%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">3</span>
    <span class="title">50%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">4</span>
    <span class="title">75%</span>
  </div>
  <span class="bar"></span>
  <div class="circle">
    <span class="label">5</span>
    <span class="title">100%</span>
  </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 2021-08-31
    • 2023-03-17
    • 2023-01-12
    • 1970-01-01
    相关资源
    最近更新 更多