YUI Library Home

YUI Library Examples: ProgressBar Control: Events

ProgressBar Control: Events

This example shows how you can use the events that ProgressBar fires.

0
255
127
Control
Value
Range

The code to create the ProgressBar is:

We instantiate the ProgressBar and configure it so that the initial value is 127, which is halfway between 0 and 255. We chose this range so that the values can translate directly into color values, which we then apply to the bar. The ProgressBar uses an Animation instance which we can get and access directly to set its duration and easing method.

We are listening to the three events related to movement:

  • start signals the start of the movement
  • progress is fired during the movement
  • complete signals the completion of the movement

Without animation, the start, progress and complete events fire one after the other in close sequence.

Our event handlers do a few simple things:

  • we display 'Started' for one second upon receiving the start event
  • we change the color of the bar itself to reflect the value received from the progress event
  • we show the current value right below the bar (all events provide the value)
  • we display 'Stopped' upon receiving the complete event

The value argument passed by all events provides the nominal value of the ProgresBar, not the size of the bar itself. A value of 50 will always be halfway in a range of 0 to 100, whether the ProgressBar is 100 or 500 pixels wide.

We have also provided a slider to change the end values for the bar so that we can show how to respond to those events and display their values. The ProgressBar inherits the attribute change events from the Element Utility, so before and after change events are available for all configuration attributes.

The markup for the text labels are shown below. Notice the yui-pb-range and yui-pb-caption class names in their declaration. The ProgressBar itself does not use those class names at all, but they are defined as part of the "Sam" skin as a convenience to the implementer.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

ProgressBar Control Examples:

More ProgressBar Control Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings