Slider
jQuery UI Slider
Overview
The jQuery UI Slider plugin makes selected elements into sliders. There are various options such as multiple handles, and ranges. The handle can be moved with the mouse or the arrow keys.
The start, slide, and stop callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
The slider widget will create handle elements with the class 'ui-slider-handle' on initialization. You can specify custom handle elements by creating and appending the elements and adding the 'ui-slider-handle' class before init. It will only create the number of handles needed to match the length of value/values. For example, if you specify 'values: [1, 5, 18]' and create one custom handle, the plugin will create the other two.
- ui.handle: DOMElement - the current focused handle
- ui.value: Integer - the current handle's value
Dependencies
- UI Core
- UI Widget
- UI Mouse
Example
$("#slider").slider();
<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <style type="text/css"> #slider { margin: 10px; } </style> <script> $(document).ready(function() { $("#slider").slider(); }); </script> </head> <body style="font-size:62.5%;"> <div id="slider"></div> </body> </html>
Options
Events
Methods
-
destroy
- Signature:
- .slider( "destroy" )
Remove the slider functionality completely. This will return the element back to its pre-init state.
-
disable
- Signature:
- .slider( "disable" )
Disable the slider.
-
enable
- Signature:
- .slider( "enable" )
Enable the slider.
-
option
- Signature:
- .slider( "option" , optionName , [value] )
Get or set any slider option. If no value is specified, will act as a getter.
-
option
- Signature:
- .slider( "option" , options )
Set multiple slider options at once by providing an options object.
-
widget
- Signature:
- .slider( "widget" )
Returns the .ui-slider element.
-
value
- Signature:
- .slider( "value" , [value] )
Gets or sets the value of the slider. For single handle sliders.
-
values
- Signature:
- .slider( "values" , index , [value] )
Gets or sets the values of the slider. For multiple handle or range sliders.
Theming
The jQuery UI Slider plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
If a deeper level of customization is needed, there are widget-specific classes referenced within the jquery.ui.slider.css stylesheet that can be modified. These classes are highlighed in bold below.
Sample markup with jQuery UI CSS Framework classes
<div class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"><a style="left: 0%;" class="ui-slider-handle ui-state-default ui-corner-all" ></a>
</div>
Note: This is a sample of markup generated by the slider plugin, not markup you should use to create a slider. The only markup needed for that is <div><div>.