Get value of YUI Progress Bar on click
I am using the yui progress bar to display ratings for a list of items. I know the progress bar inherits the "on" method, but I'm not sure how to capture wher开发者_如何学JAVAe in the progress bar the user is clicking. I'd like to get an int or double from that event. Is this possible?
ProgressBar provides no direct way to do that. However, since it inherits the on method which allows you to subscribe to events from the widget container, you can subscribe to the click event and get the X,Y coordinates of the click and compare them to the top-left corner:
myProgressBar.on('click', function (ev) {
var xyClick = YAHOO.util.Event.getXY(ev);
var xyProgressBar = YAHOO.util.Dom.getXY(this.get('element'));
// now you make the arithmetic
});
getXY returns an array with two elements, the x and y coordinates. It would be easier to use getX or getY depending on the orientation of the ProgressBar
精彩评论