Thanks to everyone who chipped in with bug reports and helpfull suggestions. There’s a pint of Guinness in the virtual keg for all of you.
Configuring the Slider
All of the Sliders configuration parameters should be defined within the input tags className attribute.
Stipulating the Sliders numeric range
To define your required range, add the className fd_range_lowerlimit_upperlimit to the associated input’s className e.g. the classname ‘fd_range_-255_255’ will give the slider a numeric range of -255 to 255. This is a required className – without it, no slider control is created.
The Animated Tween
Should the input’s className contain fd_tween, clicking on the slider bar initiates a tween animation that scrolls the slider’s “drag-handle” to the point in which the mouseDown event occurred.
Should this className be omitted, clicking on the slider bar will move the slider drag-handle 10% of the defined range in the direction of where the mouseDown event occurred. Clicking and holding down the mouse button will initiate a timer that automatically moves the drag-handle i.e. repeatedly clicking on the slider bar isn’t necessary.
Stipulating a JavaScript callback function
Should you wish the slider to call another JavaScript function each time the slider handle is moved, give the associated input a className fd_callback_callbackFunctionName e.g. the classname ‘fd_callback_updateColor’ will get the slider to call the javascript function ‘updateColor()’ each time the drag-handle moves (as can be seen in the demo).
Of course, as the function name is being declared within a CSS className, the name itself is limited to the set of alphanumeric characters valid for use within such a CSS className i.e. while the character “$” is a valid JavaScript function name, it is not a valid character for use within a CSS className and so should be avoided.
Hiding the original input
Giving the input a className of fd_hide_input will do exactly that, and hide the input element on slider creation (the default functionality is to keep the input visible).
Inputs are hidden by setting their type to “hidden” and so they still appear in the DOM and their value will be submitted to the server.
Vertical sliders
Vertical sliders can be created by adding fd_vertical to the associated input’s className.
Styling the slider
Sliders can have an additional className given to them (to enable you to style them differently to the others) by adding fd_classname_yourclassnamehere to the associated input’s className e.g. the className ‘fd_classname_hunkydory’ will give the associated slider control an extra class of ‘hunkydory’.
Additionally each slider control is given a unique ID of the form ‘fd-slider-theAssociatedInputElementsId’. This enables you to target individual sliders within the CSS and also enables DOM access to the top level slider div by using document.getElementById.
Keyboard accessibility
Once a slider has focus, the arrow keys can be used to move the drag handle (by default, the drag handle moves by 5% of the defined range), the “Home” button to move the slider to it’s minimum value and the “End” button to move the slider to it’s maximum value. Additionally, each slider is given the WAI-ARIA role of slider and it’s associated states valuemax, valuemin and valuenow.
MouseWheel support
MouseWheel support currently exists for Internet Explorer and FireFox/Mozilla.
While Opera and Safari support the mouseWheel within JavaScript, they do not support the extending of DOM elements with a tabindex for the purposes of making them keyboard accessible i.e. enabling them to support the focus and blur events; and as it’s the focus and blur events that are used to add and remove the mouseWheel event handlers, mouseWheel support is (currently) impossible in these browsers.
Bugs and annoyances
The demo uses png images for the slider drag-handles and will therefore will only display in Internet Explorer (5.5+) by using additional and proprietary css filter behaviours (which are passed using conditional comments within the demo). All other modern browsers display the png images as intended.
The License
The script is now released under a creative commons Attribution-ShareAlike 2.5 license. Should you use the script within a commercial context please think about clicking the payPal donate button – it’s certainly not an obligation but it would most certainly put a smile on my face.
Demo and download
Tested in Internet Explorer 6, Firefox and Mozilla.
View the slider demo or download the javascript source.

Previous Comments ~
http://my.opera.com/community/forums/topic.dml?id=110224
This is FANTASTIC! I’ve been looking for an accessible slider control and this one really passes the test. Thanks a million. :-)
@ Hannah: Hi Hannah, thanks for the kind words but (there’s always a but) remember, the script has not been tested on anything but Opera9, IE6 and the latest Firefox and so I can’t actually promise it won’t fall over in other browsers!
If you do encounter any bugs, please leave a comment and I’ll try to fix them in a later release.
Regards,
Brian
Hey, Gotta question for you….
If I’m passing the value from the slider to a new page via GET, how can I tell the slider to relocate the handle to that spot. I tried just setting the value of the input tag, but that doesn’t seem to work – the site as a whole uses the corret value, but the slider itself doesn’t relocate. :(
Any ideas?
@ Al: Hi Al, the slider should calculate the initial handle position using the input’s value (i.e. the demo sets the rgb sliders to 128 as that’s the initial value of the associated input).
If you mean “set the slider value through javascript”, I shall have to tweak the code to enable you to grab the slider object and call the “calcFromInput” method (after you have changed the input’s value).
I’ll see if I can grab a few minutes today to change the code for you.
Regards,
Brian.
@ Al: Hi again, well, I changed the code to enable you to reference individual slider objects through JavaScript. You can now change the input’s value and then call:
fdSliderController.sliders[“the associated input’s name here”].recalculate()
to get the slider to recalculate the handle position.
The code change does mean that each input has to have a unique name.
Hope this helps,
Brian.
Thank you Brian, this is perfect. I have been looking around for a slider like this, not even knowing if it would be possible, and I think this might be perfect for the project I am working on.
Any results in the testing, I will report back here.
I tested your unobrusive slider v0.1 demo. Great work. But was the vertical slider marker meant to go up/down while pressing down/up on the keyboard?
Very cool design here – In my opinion you should work together with some joomla specialists to improve the components of their cms. ;)
saLOUt
@ Lars: Hi Lars, I’ll try to cleanup the code a bit this week for you. Thanks for the “live” testing!
@ saLOUt: Hi, no, the vertical slider does this as I didn’t have time to complete the code. It should be very easy to fix (finish). I’ll see what I can do this week.
Update: I've updated the code to correctly handle the vertical slider option and also to accept negative values for the sliders numeric range.
Regards,
Brian.
Hi, I’m using your fantastic little tool in Firefox and have noticed a little bug. The sliders don’t seem to function correctly when the minimum value isn’t zero.
For example, one of the sliders has the class: _fd_range_50_75_. When moving the slider, the input value doesn’t change at all until it’s positioned at the farthest right position, when it changes to 75.
Another example is when I have the slider class: _fd_range_10000_100000_. The slider, in this case, only allows the value to go up to 80000.
Any help would be greatly appreciated.
Thanks
Ronnie
@ Ronnie: Hi Ronnie, I’ve fixed the problem; also, the vertical slider now increments in a more logical fashion i.e. the top of the vertical slider now relates to the max value (and not the min value as was previously the case).
Thanks for the bug report.
Regards,
Brian.
HI there, I think this is the slider I’m afer (after searching around – a lot !). I have downloaded the .js and the style in the view source of the demo page. Can you tell me where I change the slider being used please ?
I assume it is in the below but I can’t seem to direct it to the slider png I want. .
.fd-slider-handle
{ position:absolute; top:0; left:0; width:20px; height:20px; background:transparent url(slider.png) no-repeat 0px 0px !important; background:none; -moz-user-select:none; }.fd-slider-hover { background:transparent url(slider-1.png) no-repeat 0px 0px !important; background:none; }
Hi ther, me again.
Not to worry, I have worked it out. I’m doing this in .NET 2.0 (which I’m very new to). I just moved the .png files into the Themes folder where my style sheet is. I don’t actually know the syntax for referencing a different part of the folder structure ! (yep, this is quite a struggle for me at the moment).
Thanks for the control, it looks great and is certinaly fit for the purpose for which I need it.
Many thanks,
Chris
@ Chris: Hi Chris, glad you got it working…
Hi Brian,
I just wanted to say thanks for creating this control. It is awesome and is helping me to understand javascript and css. Brilliant !
People like you are the heart and soul of the development community. I really appreciate your efforts.
All the best,
Chris
Hi Brian,
Thank you so much for this great slider control! I am running into a problem and hopefully you can help. When the slider is set to vertical, it has no problems accepting a negative starting value. However, when it is set to horizontal mode, the negative value no longer works and slider control ceases to function. Any help or insight would be greatly appreciated.
Thanks!
Nich
@ Nich: Hi Nich, I’ve an updated version of the slider code (which I shall post this week within a new article) that addresses this and various other concerns. I’ll send it onto you via email in the interim.
Hello Brian,
Wow this looks great! I’d like to use it in a little drawing web app I’m creating (Nothing commercial yet!) But I’d still like to add credits for code I don’t write myself. I’m a graduate student, so I’ve got the ‘citing sources’ bug. This program is however not a school project. Do you have a preference for how you’d like to be credited?
Thanks again
-Luke
Comments are currently closed but feel free to contact me on twitter with your questions or suggestions - I’d love to hear from you.