This example shows how you can use the events that ProgressBar fires.
The code to create the ProgressBar is:
1 | var pb = new YAHOO.widget.ProgressBar({ |
2 | value:127, |
3 | maxValue:255, |
4 | anim:true |
5 | }).render('pbContainer'); |
6 | var anim = pb.get('anim'); |
7 | anim.duration = 3; |
8 | anim.method = YAHOO.util.Easing.bounceBoth; |
view plain | print | ? |
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 movementprogress
is fired during the movementcomplete
signals the completion of the movementWithout animation, the start
, progress
and complete
events fire one after the other in close sequence.
1 | pb.on('start',function (value) { |
2 | Dom.get('status').innerHTML = 'Started'; |
3 | window.setTimeout(function() { |
4 | Dom.get('status').innerHTML = ''; |
5 | },1000); |
6 | }); |
7 | |
8 | pb.on('progress',function (value) { |
9 | Dom.setStyle(this.get('barEl'),'backgroundColor','rgb(' + value + ',' + value + ',127)'); |
10 | Dom.get('valueContainer').innerHTML = value; |
11 | }); |
12 | |
13 | pb.on('complete',function (value) { |
14 | Dom.get('status').innerHTML = 'Stopped'; |
15 | window.setTimeout(function() { |
16 | Dom.get('status').innerHTML = ''; |
17 | },1000); |
18 | }); |
view plain | print | ? |
Our event handlers do a few simple things:
start
eventvalue
received from the progress
eventvalue
)complete
eventThe 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.
1 | pb.on('minValueChange',function(oArgs) { |
2 | Dom.get('minValueContainer').innerHTML = oArgs.newValue; |
3 | }); |
4 | |
5 | pb.on('maxValueChange',function(oArgs) { |
6 | Dom.get('maxValueContainer').innerHTML = oArgs.newValue; |
7 | }); |
view plain | print | ? |
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.
1 | <div id="textContainers"> |
2 | <div id="minValueContainer" class="yui-pb-range">0</div> |
3 | <div id="maxValueContainer" class="yui-pb-range">255</div> |
4 | <div class="yui-pb-caption"> |
5 | <span id="valueContainer">127</span> |
6 | <span id="status"></span> |
7 | </div> |
8 | </div> |
view plain | print | ? |
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.
INFO 117ms (+1) 8:12:22 PM:
ProgressBar
set value: 127
INFO 116ms (+0) 8:12:22 PM:
ProgressBar
Recalculating auxiliary factors
INFO 116ms (+0) 8:12:22 PM:
ProgressBar
Redraw
INFO 116ms (+0) 8:12:22 PM:
ProgressBar
start render
INFO 116ms (+0) 8:12:22 PM:
ProgressBar
Turning animation on
INFO 116ms (+1) 8:12:22 PM:
ProgressBar
set value: 127
INFO 115ms (+1) 8:12:22 PM:
ProgressBar
Initializing configuration attributes
INFO 114ms (+22) 8:12:22 PM:
ProgressBar
Creating ProgressBar instance
INFO 92ms (+92) 8:12:22 PM:
LogReader instance0
LogReader initialized
INFO 0ms (+0) 8:12:22 PM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings