Getting Started With jQuery UI
Getting Started With jQuery UI
Written by Ian Elliot   
Monday, 28 January 2013
Article Index
Getting Started With jQuery UI
Doing more with the Slider


Slider Settings

This gives you the basic operation of a slider - what else can you change?

You can set the max and min values that the slider will return via the max and min properties. You can also set the step size, i.e the amount the slider moves each time using the step property. Finally you can set the orientation using the orientation property.

So, for example, to set up a vertical slider working between 1 and -1 with a step size of 0.1 and a display of the value as the user moves the slider.

The HTML can be as simple as:

<div id="mySliderDiv">
<div id="myText">

 The code is:

       max:1, min:-1,
       slide: function(event, ui) {

If you run this then you will see a vertical slider with the current value changing below it as the user moves the slider.



Range Slider

As well as the standard slider you can also implement a range slider - one that has two sliders, allowing the user to setup a max and min for a range.

All you have to do is set the range property to true and then set values to an array giving the max and min properties of the two sliders.

For example


creates a slider with two slides ranging between 0 and 100 and one initially set to 25 and the other to 75. You can also have a slider with a fixed max or min by setting the range to "max" or "min"

You can get the values for the sliders using the  values() or value(index) methods. For example

var values=$("#mySliderDiv").slider("values);

returns an array of values.

Changing the Style

You might not be happy with the default style of the slider. To change it all you have is create a new style sheet that applies styles to the standard classes set up by the constructor.

You can find out the classes that are used by examining the slider element using Firebug say:

<div id="mySliderDiv"
 <a class="ui-slider-handle
           ui-corner-all" href="#">

From this you can see that to customize the slider handle you need to modify the ui-slider-handle, the ui-state-default or the  ui-corner-all class. The problem is always finding out which one to change.

You can create complete themed sets of styles using the ThemeRoller where you will also find predefined styles you can use.

If you want to do something radical to the slider handle then the best approach is to just jQuery to remove the assigned styles and apply your own.


jQuery 3 - Understanding jQuery

jQuery - you can't help hearing about it, but it can seem a bit mysterious. jQuery experts seem to just write compact impenetrable code and even seeing what it is supposed to be doing can be tough. Th [ ... ]

Javascript Data Structures - Stacks, Queue and Deque

Stacks, queues and deques are the most basic of the slightly more advanced data structures you will meet. The good news is that they are very, very easy to implement in JavaScript.

Other Articles

Last Updated ( Tuesday, 25 August 2015 )

Copyright © 2016 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.