| Page 1 of 1 | [ 5 posts ] |
|
I want to create a slider where the gutter to the left of the thumb is filled with a solid color. Sort of a dynamic bar graph effect. I also want to be able to change that color as the slider is moved from min to max. The problem I'm having is that I'm new to YUI and I can't figure out which mechanism I should be using to add this functionality. Can someone give me a pointer on whether I should be extending something or augmenting or mixing or what? And any other thoughts on good ideas or things to watch for?
What I've got so far is a custom rail-x.png with a solid outside color and a transparent center gutter, and I can manually put a div behind it and color it as I want. Now I want to make this div an automatic feature that is automatically sized to match the distance from the min end to the thumb, and maybe provide min/max colors and the slider can interpolate. Haven't thought too much about that bit, actually. |
Juan Ignacio DopazoYUI Contributor
|
You should look at the Creating your own Widgets section of the Docs. That will give you a nice tour on how to create widgets. In this case instead of extending Y.Widget, you'll just be extending Y.Slider.
Once you have your DOM structure set up all you need to do is use the Slider events to sync your new DOM nodes. In this case you'll probably want to listen to the 'valueChange' event and set the width of your colored node to the position of the slider handle. Code: Y.MySlider = Y.Base.create('mySlider', Y.Slider, [], { initializer: function () { this.after('valueChange', this._syncColoredBar); }, _syncColoredBar: function (e) { // e.newVal has the new value of the slider (a value between the min and max attributes) this._coloredNode.setStyle('width', parseInt(this.get('length'), 10) * e.newVal / this.get('max')); } }); The fun part will be to figure out a function that takes a number between 0 and 100 (a percentage) and returns a color between two other colors. |
|
Thank you very much for that, Juan, that's a great start.
I need to solve one problem before I can begin to work with it though; all the YUI class names have been changed from yui-slider-(foo) to yui-myslider-(foo), which results in none of the appropriate YUI styles being applied. There must be some way to tell it to use the superclass' "name" property for the purpose of constructing css class names? As for the colors, I'm thinking I can probably get away with a red-green hue line in HSB space and convert that to RGB. Or maybe I can stick with a static color, boss willing. |
|
Okay, that may have been a stupid question. Changing Base.Create('mySlider', ...) to Base.create('slider', ...) in the Base.create() call seems to make the class name creation work fine. Looks like it was designed that way, almost!
I'm hoping I won't be stomping on some superclass events or something by using the same name, but if so I'm sure you'll all hear from me again soon enough. Thanks again, - Bruce |
Juan Ignacio DopazoYUI Contributor
|
Yes, YUI widgets use a NAME property in the constructor to set class names. That's what you're setting with the first parameter of Y.Base.create().
Bruce wrote: As for the colors, I'm thinking I can probably get away with a red-green hue line in HSB space and convert that to RGB. That was my first thought as well. Try to do it! It sounds fun. If you get stuck, ask here or at #yui on IRC. |
| Page 1 of 1 | [ 5 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group