English 中文(简体)
JqueryUI - Progressbar
  • 时间:2024-11-05

JqueryUI - Progressbar


Previous Page Next Page  

Progress bars indicate the completion percentage of an operation or process. We can categorize progress bar as determinate progress bar and indeterminate progress bar.

Determinate progress bar should only be used in situations where the system can accurately update the current status. A determinate progress bar should never fill from left to right, then loop back to empty for a single process.

If the actual status cannot be calculated, an indeterminate progress bar should be used to provide user feedback.

jQueryUI provides an easy-to-use progress bar widget that we can use to let users know that our apppcation is hard at work performing the requested operation. jQueryUI provides progressbar() method to create progress bars.

Syntax

The progressbar() method can be used in two forms −

$ (selector, context).progressbar (options) Method

The progressbar (options) method declares that an HTML element can be managed in the form of a progress bar. The options parameter is an object that specifies the appearance and behavior of progress bars.

Syntax

$(selector, context).progressbar (options);

You can provide one or more options at a time using Javascript object. If there are more than one options to be provided then you will separate them using a comma as follows −

$(selector, context).progressbar({option1: value1, option2: value2..... });

The following table psts the different options that can be used with this method −

Sr.No. Option & Description
1

This option when set to true disables the progress bars. By default its value is false.

Option - disabled

This option when set to true disables the progress bars. By default its value is false.

Syntax

$( ".selector" ).progressbar({ disabled: true });
2

This option sets the maximum value for a progress bar. By default its value is 100.

Option - max

This option sets the maximum value for a progress bar. By default its value is 100.

Syntax

$( ".selector" ).progressbar({ max: 500});
3

This option specifies the initial value of the progress bar. By default its value is 0.

Option - value

This option specifies the initial value of the progress bar. By default its value is 0.

Syntax

$( ".selector" ).progressbar({ value: 20 });

The following section will show you a few working examples of progressbar functionapty.

Default Functionapty

The following example demonstrates a simple example of progressbar functionapty, passing no parameters to the progressbar() method.

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI ProgressBar functionapty</title>
      <pnk href = "https://code.jquery.com/ui/1.10.4/themes/ui-pghtness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      
      <style>
         .ui-widget-header {
            background: #cedc98;
            border: 1px sopd #DDDDDD;
            color: #333333;
            font-weight: bold;
         }
      </style>
      
      <script>
         $(function() {
            $( "#progressbar-1" ).progressbar({
               value: 30
            });
         });
      </script>
   </head>
   
   <body> 
      <span id = "progressbar-1"></span> 
   </body>
</html>

Let us save the above code in an HTML file progressbarexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −