【问题标题】:how to make a progress bar with jquery?如何用jquery制作进度条?
【发布时间】:2012-02-07 13:34:48
【问题描述】:

我想知道如何将其制作为简单的代码。我在一个网站上找到了一些我想用于我正在开发的网站的东西。问题是我试图把它放在我的网站中(一个非常简单的),但我无法让它工作。
有谁知道我怎样才能使它成为一个简单的代码?

This is what I found.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>eBay PayPal</title>
<style type="text/css">
*{margin:0; padding:0;}
body{background:#FFFFFF url(images/1.jpg) top left no-repeat; width:1099px; height:1050px;}
</style>
<script src="http://jquery-ui.googlecode.com/svn/tags/1.7.2/jquery-1.3.2.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" type="text/javascript"></script>



<script type="text/javascript">
$(document).ready(function(){
    var p=0;
    $("#myProgressBar").progressbar({value:0});
        var timer = setInterval(function(){
            //This animates the bar
            $("#myProgressBar .ui-progressbar-value").animate({width: p+"%"},500);
            //This does static sets of the value
            //$("#myProgressBar").progressbar("option","value",p);
            p = p +33.33;
            if(p>33.33){
                $("#myProgressBar .ui-progressbar-value").animate({width: "33.33%"}, 500);
                //$("#myProgressBar").progressbar("option","value",100);
                clearInterval(timer);
            }
    },500);
});
</script>

</head>

<body>
<a href="2.html" style="width:185px; height:31px;position:absolute; left: 198px; top: 516px;"></a>
<div id='myProgressBar' style="position:absolute; border:1px red solid; height:41px; width:950px; left: 69px; top: 608px;"></div>
</body>
</html>`

我想知道是否有人可以帮助我,基本上我只想要一个带有进度条的页面。卡

【问题讨论】:

    标签: jquery


    【解决方案1】:

    这可能会有所帮助:

    http://docs.jquery.com/UI/Progressbar

    那里有代码示例,应该可以让您轻松制作进度条。

    【讨论】:

    • 非常感谢您的帮助,您知道如何制作动画吗?
    • 没问题,我想这个答案会对你有所帮助:stackoverflow.com/questions/5047498/….
    • 你知道为什么我的代码现在可以工作了吗? jsfiddle.net/gPfBC 当我试图让它在我的 html 文件中工作时,它就是不工作!
    • 嘿,对不起,我今天早上才回来。我觉得你有点太复杂了,看看这个并告诉我它是否有效:jsfiddle.net/gPfBC。它似乎对我有用。
    【解决方案2】:

    我对已经开发的progressbar 概念进行了改进,该概念仅基于 jquery 和 CSS。 查看以下链接了解其详细信息:

    http://progressbar-simple.blogspot.com/

    希望对您有所帮助。

    【讨论】:

    • 我在我的项目中集成了相同的进度条,但在 IE 10+ 中我面临进度条更新延迟。我添加了以下语句以改善进度条 uploadProgess.find('div').animate({ width: progressBarWidth }, { queue: false, duration: 100 }).html(this.uploadPercentage + "%&nbsp") 的滞后;但它仍然有点滞后。任何其他提高性能的想法。
    【解决方案3】:

    想要使用Bootstrap 4的朋友可以使用:

    var delay = 500;
    $(".progress-bar").each(function(i) {
      $(this).delay(delay * i).animate({
        width: $(this).attr('aria-valuenow') + '%'
      }, delay);
    
      $(this).prop('Counter', 0).animate({
        Counter: $(this).text()
      }, {
        duration: delay,
        // easing: 'swing',
        step: function(now) {
          $(this).text(Math.ceil(now) + '%');
        }
      });
    });
    .progress {
      margin-bottom: 20px;
    }
    
    .progress-bar {
      width: 0;
    }
    
    .progress .progress-bar {
      transition: unset;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    
    <div class="container">
      <h2>Bootstrap 4 Progress Bars</h2>
      <div class="progress border">
        <div class="progress-bar progress-bar-striped progress-bar-animated bg-info" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">70</div>
      </div>
      <div class="progress border">
        <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">50</div>
      </div>
      <div class="progress border">
        <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="90" aria-valuemin="0" aria-valuemax="100">90</div>
      </div>
    </div>

    【讨论】:

      【解决方案4】:

      必需的 JS/CSS

      CSS:-
      1.bootstrap.min.css
      2.jquery-ui.min.css

      JS:-
      1.jquery-3.3.1.js
      2.bootstrap.min.js
      3.jquery-ui-1.12.1.min.js

      下面是附加css和JS文件的顺序

      <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
      <link href="~/Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
      
      
      <script src="~/Scripts/jquery-3.3.1.js"></script>
      <script src="~/Scripts/bootstrap.min.js"></script>>
      <script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
      

      CSS

      .ui-progressbar .ui-progressbar-overlay {
          background: none !important;
      }
      
      .ui-widget.ui-widget-content {
      }
      
      .ui-progressbar {
          position: relative;
          color: #362878;
          width: 100%;
          height: 25px;
          background-color: #778899;
          margin-left: auto;
          margin-right: auto;
      }
      
      .progress-label {
          color: white;
          position: absolute;
          left: 50%;
          top: 0px;
          /* font-weight: bold; */
          /* text-shadow: 1px 1px 0 #fff; */
          margin-left: -40px;
      }
      
      .ui-widget-header {
          border: 1px solid #E8D1CF;
          font-weight: bold;
          margin-left: -40px;
          background-color: lightslategrey;
      }
      

      HTML

      <div class="row">
      <div class="form-group col-sm-6">
          <label>Job Title</label>
          <input type="text" class="form-control progInput" data-pbVal="25">
      </div>
      
      <div class="form-group col-sm-6">
          <label>First Name</label>
          <input type="text" class="form-control progInput" data-pbVal="25">
      </div>
      
      <div class="form-group col-sm-6">
          <label>Last Name</label>
          <input type="text" class="form-control progInput" data-pbVal="25">
      </div>
      
      <div class="form-group col-sm-6">
          <label>Email</label>
          <input type="text" class="form-control progInput" data-pbVal="25">
      </div>
      

      JavaScript/JQuery

      <script>
          var progressbar = $("#progressbar"),
              progressLabel = $(".progress-label");
      
          progressbar.progressbar({
              value: false,
              change: function () {
                  progressLabel.text(progressbar.progressbar("value") + "%");
              },
              complete: function () {
                  progressLabel.text("100%");
              }
          });
      
          function progress(value) {
              var val = progressbar.progressbar("value") || 0;
              progressbar.progressbar("value", parseInt(value));
              switch (parseInt(value)) {
                  case 0:
                      $('.ui-widget-header').css('background-color', '#778899');
                      break;
                  case 25:
                      $('.ui-widget-header').css('background-color', 'red');
                      break;
                  case 50:
                      $('.ui-widget-header').css('background-color', 'orange');
                      break;
                  case 75:
                      $('.ui-widget-header').css('background-color', '#bfff80');
                      break;
                  case 100:
                      $('.ui-widget-header').css('background-color', '#408000');
                      break;
                  default:
                      $('.ui-widget-header').css('background-color', '#778899');
              }
      
          }
      
          $(".progInput").change(function () {
              var pbVal = 0;
              $(".progInput").each(function (index) {
                  if ($(this).val().length > 0) {
                      pbVal += parseInt($(this).attr('data-pbVal'));
                  }
                  if (pbVal > 0) {
                      progress(pbVal)
                  }
                  else {
                      progress(0);
                  }
              });
              return false;
          });
      </script>
      

      这是输出

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-13
        • 2011-04-14
        • 2011-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-25
        相关资源
        最近更新 更多