This example shows how you can use the events that ProgressBar fires.
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:
startsignals the start of the movement
progressis fired during the movement
completesignals the completion of the movement
Without animation, the
complete events fire one after the other in close sequence.
Our event handlers do a few simple things:
valuereceived from 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
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.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.