How to make a progress bar

后端 未结 19 1488
失恋的感觉
失恋的感觉 2020-12-04 18:09

How would one go about making a progress bar in html/css/javascript. I don\'t really want to use Flash. Something along the lines of what can be found here: http://dustincur

相关标签:
19条回答
  • 2020-12-04 18:39

    You could recreate the progress bar using CSS3 animations to give it a better look.

    JSFiddle Demo

    HTML

    <div class="outer_div">
        <div class="inner_div">
            <div id="percent_count">
    
        </div>
    </div>
    

    CSS/CSS3

    .outer_div {
        width: 250px;
        height: 25px;
        background-color: #CCC;
    }
    
    .inner_div {
        width: 5px;
        height: 21px;
        position: relative; top: 2px; left: 5px;
        background-color: #81DB92;
        box-shadow: inset 0px 0px 20px #6CC47D;
        -webkit-animation-name: progressBar;
        -webkit-animation-duration: 3s;
        -webkit-animation-fill-mode: forwards;
    }
    
    #percent_count {
        font: normal 1em calibri;
        position: relative;
        left: 10px;
    }
    
    @-webkit-keyframes progressBar {
        from {
            width: 5px;
        }
        to {
            width: 200px;
        }
    }
    
    0 讨论(0)
  • 2020-12-04 18:41
    var myPer = 35;
    $("#progressbar")
        .progressbar({ value: myPer })
        .children('.ui-progressbar-value')
        .html(myPer.toPrecision(3) + '%')
        .css("display", "block");
    
    0 讨论(0)
  • 2020-12-04 18:41

    If you need to show and hide progress bar inside your php and java script, then follow this step.Its a complete solution, no need of any library etc.

               //Design Progress Bar
    
      <style>
    #spinner
    {     
    position: absolute;
    left: 50%;
    top: 50%;
    background-color: white;
    z-index: 100;
    
    height: 200px;
    
    
    width: 300px;
    margin-left: -300px;
    
        /*Change your loading image here*/
       background: url(images/loading12.gif) 50% 50% no-repeat ;
    
    }
      </style>
    
                   //Progress Bar inside your Page
    
    <div id="spinner" style=" display:none; ">
    </div>                                
    
        // Button to show and Hide Progress Bar
    <input class="submit" onClick="Show()" type="button" value="Show" /> 
    <input class="submit" onClick="Hide()" type="button" value="Hide" /> 
    
                //Java Script Function to Handle Button Event     
    <script language="javascript" type="text/javascript">
     function Show()
     {       
      document.getElementById("spinner").style.display = 'inline';
     }
    function Hide()
     {       
      document.getElementById("spinner").style.display = 'none';
     }
    
    </script>
    

    Image link: Download image from here

    0 讨论(0)
  • 2020-12-04 18:41

    You can use setInterval to create a progress bar.

    function animate() {
      var elem = document.getElementById("bar");   
      var width = 1;
      var id = setInterval(frame, 10);
      function frame() {
        if (width >= 100) {
          clearInterval(id);
        } else {
          width++; 
          elem.style.width = width + '%'; 
        }
      }
    }
    #progress-bar-wrapper {
      width: 100%;
      background-color: #ffffd;
    }
    
    #bar {
      width: 1%;
      height: 30px;
      background-color: orange;
    }
    <div id="progress-bar-wrapper">
      <div id="bar"></div>
    </div>
    
    <br>
    <button onclick="animate()">Click Me</button>

    0 讨论(0)
  • 2020-12-04 18:42

    http://jqueryui.com/demos/progressbar/

    Check that out, it might be what you need.

    0 讨论(0)
  • 2020-12-04 18:42

    Basically its this: You have three files: Your long running PHP script, a progress bar controlled by Javascript (@SapphireSun gives an option), and a progress script. The hard part is the Progress Script; your long script must be able to report its progress without direct communication to your progress script. This can be in the form of session id's mapped to progress meters, a database, or check of whats not finished.

    The process is simple:

    1. Execute your script and zero out progress bar
    2. Using AJAX, query your progress script
    3. Progress script must somehow check on progress
    4. Change the progress bar to reflect the value
    5. Clean up when finished
    0 讨论(0)
提交回复
热议问题