2
<ul class="UIAPIPlugin-toc">
3
<li><a href="#overview">Overview</a></li>
4
<li><a href="#options">Options</a></li>
5
<li><a href="#events">Events</a></li>
6
<li><a href="#methods">Methods</a></li>
7
<li><a href="#theming">Theming</a></li>
9
<div class="UIAPIPlugin">
10
<h1>jQuery UI Slider</h1>
12
<h2 class="top-header">Overview</h2>
13
<div id="overview-main">
14
<p>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.</p>
15
<p>All 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'):
18
<li><b>ui.handle</b>: DOMElement - the current focused handle
19
<li><b>ui.value</b>: Integer - the current handle's value
22
<div id="overview-dependencies">
28
<div id="overview-example">
30
<div id="overview-example" class="example">
31
<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
32
<p><div id="demo" class="tabs-container" rel="">
33
A simple jQuery UI Slider.<br />
35
<pre>$("#slider").slider();
37
<p></div><div id="source" class="tabs-container">
39
<pre><!DOCTYPE html>
42
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
43
<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
44
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
45
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.slider.js"></script>
46
<style type="text/css">
47
#slider { margin: 10px; }
49
<script type="text/javascript">
50
$(document).ready(function(){
51
$("#slider").slider();
55
<body style="font-size:62.5%;">
57
<div id="slider"></div>
67
<h2 class="top-header">Options</h2>
68
<ul class="options-list">
70
<li class="option" id="option-animate">
71
<div class="option-header">
72
<h3 class="option-name"><a href="#option-animate">animate</a></h3>
74
<dt class="option-type-label">Type:</dt>
75
<dd class="option-type">Boolean</dd>
77
<dt class="option-default-label">Default:</dt>
78
<dd class="option-default">false</dd>
82
<div class="option-description">
83
<p>Whether to slide handle smoothly when user click outside handle on the bar.</p>
85
<div class="option-examples">
86
<h4>Code examples</h4>
87
<dl class="option-examples-list">
90
Initialize a slider with the <code>animate</code> option specified.
93
<pre><code>$('.selector').slider({ animate: true });</code></pre>
98
Get or set the <code>animate</code> option, after init.
102
var animate = $('.selector').slider('option', 'animate');
104
$('.selector').slider('option', 'animate', true);</code></pre>
112
<li class="option" id="option-max">
113
<div class="option-header">
114
<h3 class="option-name"><a href="#option-max">max</a></h3>
116
<dt class="option-type-label">Type:</dt>
117
<dd class="option-type">Number</dd>
119
<dt class="option-default-label">Default:</dt>
120
<dd class="option-default">100</dd>
124
<div class="option-description">
125
<p>The maximum value of the slider.</p>
127
<div class="option-examples">
128
<h4>Code examples</h4>
129
<dl class="option-examples-list">
132
Initialize a slider with the <code>max</code> option specified.
135
<pre><code>$('.selector').slider({ max: 7 });</code></pre>
140
Get or set the <code>max</code> option, after init.
144
var max = $('.selector').slider('option', 'max');
146
$('.selector').slider('option', 'max', 7);</code></pre>
154
<li class="option" id="option-min">
155
<div class="option-header">
156
<h3 class="option-name"><a href="#option-min">min</a></h3>
158
<dt class="option-type-label">Type:</dt>
159
<dd class="option-type">Number</dd>
161
<dt class="option-default-label">Default:</dt>
162
<dd class="option-default">0</dd>
166
<div class="option-description">
167
<p>The minimum value of the slider.</p>
169
<div class="option-examples">
170
<h4>Code examples</h4>
171
<dl class="option-examples-list">
174
Initialize a slider with the <code>min</code> option specified.
177
<pre><code>$('.selector').slider({ min: -7 });</code></pre>
182
Get or set the <code>min</code> option, after init.
186
var min = $('.selector').slider('option', 'min');
188
$('.selector').slider('option', 'min', -7);</code></pre>
196
<li class="option" id="option-orientation">
197
<div class="option-header">
198
<h3 class="option-name"><a href="#option-orientation">orientation</a></h3>
200
<dt class="option-type-label">Type:</dt>
201
<dd class="option-type">String</dd>
203
<dt class="option-default-label">Default:</dt>
204
<dd class="option-default">'auto'</dd>
208
<div class="option-description">
209
<p>Normally you don't need to set this option because the plugin detects the slider orientation automatically. If the orientation is not correctly detected you can set this option to 'horizontal' or 'vertical'.</p>
211
<div class="option-examples">
212
<h4>Code examples</h4>
213
<dl class="option-examples-list">
216
Initialize a slider with the <code>orientation</code> option specified.
219
<pre><code>$('.selector').slider({ orientation: 'vertical' });</code></pre>
224
Get or set the <code>orientation</code> option, after init.
228
var orientation = $('.selector').slider('option', 'orientation');
230
$('.selector').slider('option', 'orientation', 'vertical');</code></pre>
238
<li class="option" id="option-range">
239
<div class="option-header">
240
<h3 class="option-name"><a href="#option-range">range</a></h3>
242
<dt class="option-type-label">Type:</dt>
243
<dd class="option-type">Boolean, String</dd>
245
<dt class="option-default-label">Default:</dt>
246
<dd class="option-default">false</dd>
250
<div class="option-description">
251
<p>If set to true, the slider will detect if you have two handles and create a stylable range element between these two. Two other possible values are 'min' and 'max'. A min range goes from the slider min to one handle. A max range goes from one handle to the slider max.</p>
253
<div class="option-examples">
254
<h4>Code examples</h4>
255
<dl class="option-examples-list">
258
Initialize a slider with the <code>range</code> option specified.
261
<pre><code>$('.selector').slider({ range: 'min' });</code></pre>
266
Get or set the <code>range</code> option, after init.
270
var range = $('.selector').slider('option', 'range');
272
$('.selector').slider('option', 'range', 'min');</code></pre>
280
<li class="option" id="option-step">
281
<div class="option-header">
282
<h3 class="option-name"><a href="#option-step">step</a></h3>
284
<dt class="option-type-label">Type:</dt>
285
<dd class="option-type">Number</dd>
287
<dt class="option-default-label">Default:</dt>
288
<dd class="option-default">1</dd>
292
<div class="option-description">
293
<p>Determines the size or amount of each interval or step the slider takes between min and max. The full specified value range of the slider (max - min) needs to be evenly divisible by the step.</p>
295
<div class="option-examples">
296
<h4>Code examples</h4>
297
<dl class="option-examples-list">
300
Initialize a slider with the <code>step</code> option specified.
303
<pre><code>$('.selector').slider({ step: 5 });</code></pre>
308
Get or set the <code>step</code> option, after init.
312
var step = $('.selector').slider('option', 'step');
314
$('.selector').slider('option', 'step', 5);</code></pre>
322
<li class="option" id="option-value">
323
<div class="option-header">
324
<h3 class="option-name"><a href="#option-value">value</a></h3>
326
<dt class="option-type-label">Type:</dt>
327
<dd class="option-type">Number</dd>
329
<dt class="option-default-label">Default:</dt>
330
<dd class="option-default">0</dd>
334
<div class="option-description">
335
<p>Determines the value of the slider, if there's only one handle. If there is more than one handle, determines the value of the first handle.</p>
337
<div class="option-examples">
338
<h4>Code examples</h4>
339
<dl class="option-examples-list">
342
Initialize a slider with the <code>value</code> option specified.
345
<pre><code>$('.selector').slider({ value: 37 });</code></pre>
350
Get or set the <code>value</code> option, after init.
354
var value = $('.selector').slider('option', 'value');
356
$('.selector').slider('option', 'value', 37);</code></pre>
364
<li class="option" id="option-values">
365
<div class="option-header">
366
<h3 class="option-name"><a href="#option-values">values</a></h3>
368
<dt class="option-type-label">Type:</dt>
369
<dd class="option-type">Array</dd>
371
<dt class="option-default-label">Default:</dt>
372
<dd class="option-default">null</dd>
376
<div class="option-description">
377
<p>This option can be used to specify multiple handles. If range is set to true, the length of 'values' should be 2.</p>
379
<div class="option-examples">
380
<h4>Code examples</h4>
381
<dl class="option-examples-list">
384
Initialize a slider with the <code>values</code> option specified.
387
<pre><code>$('.selector').slider({ values: [1,5,9] });</code></pre>
392
Get or set the <code>values</code> option, after init.
396
var values = $('.selector').slider('option', 'values');
398
$('.selector').slider('option', 'values', [1,5,9]);</code></pre>
408
<h2 class="top-header">Events</h2>
409
<ul class="events-list">
411
<li class="event" id="event-start">
412
<div class="event-header">
413
<h3 class="event-name"><a href="#event-start">start</a></h3>
415
<dt class="event-type-label">Type:</dt>
416
<dd class="event-type">slidestart</dd>
419
<div class="event-description">
420
<p>This event is triggered when the user starts sliding.</p>
422
<div class="event-examples">
423
<h4>Code examples</h4>
424
<dl class="event-examples-list">
427
Supply a callback function to handle the <code>start</code> event as an init option.
430
<pre><code>$('.selector').slider({
431
start: function(event, ui) { ... }
437
Bind to the <code>start</code> event by type: <code>slidestart</code>.
440
<pre><code>$('.selector').bind('slidestart', function(event, ui) {
450
<li class="event" id="event-slide">
451
<div class="event-header">
452
<h3 class="event-name"><a href="#event-slide">slide</a></h3>
454
<dt class="event-type-label">Type:</dt>
455
<dd class="event-type">slide</dd>
458
<div class="event-description">
459
<p>This event is triggered on every mouse move during slide. Use ui.value (single-handled sliders) to obtain the value of the current handle, $(..).slider('value', index) to get another handles' value.
460
</p><p>Return false in order to prevent a slide, based on ui.value.</p>
462
<div class="event-examples">
463
<h4>Code examples</h4>
464
<dl class="event-examples-list">
467
Supply a callback function to handle the <code>slide</code> event as an init option.
470
<pre><code>$('.selector').slider({
471
slide: function(event, ui) { ... }
477
Bind to the <code>slide</code> event by type: <code>slide</code>.
480
<pre><code>$('.selector').bind('slide', function(event, ui) {
490
<li class="event" id="event-change">
491
<div class="event-header">
492
<h3 class="event-name"><a href="#event-change">change</a></h3>
494
<dt class="event-type-label">Type:</dt>
495
<dd class="event-type">slidechange</dd>
498
<div class="event-description">
499
<p>This event is triggered on slide stop, or if the value is changed programmatically (by the <code>value</code> method). Takes arguments event and ui. Use event.orginalEvent to detect whether the value changed by mouse, keyboard, or programmatically. Use ui.value (single-handled sliders) to obtain the value of the current handle, $(this).slider('values', index) to get another handle's value.</p>
501
<div class="event-examples">
502
<h4>Code examples</h4>
503
<dl class="event-examples-list">
506
Supply a callback function to handle the <code>change</code> event as an init option.
509
<pre><code>$('.selector').slider({
510
change: function(event, ui) { ... }
516
Bind to the <code>change</code> event by type: <code>slidechange</code>.
519
<pre><code>$('.selector').bind('slidechange', function(event, ui) {
529
<li class="event" id="event-stop">
530
<div class="event-header">
531
<h3 class="event-name"><a href="#event-stop">stop</a></h3>
533
<dt class="event-type-label">Type:</dt>
534
<dd class="event-type">slidestop</dd>
537
<div class="event-description">
538
<p>This event is triggered when the user stops sliding.</p>
540
<div class="event-examples">
541
<h4>Code examples</h4>
542
<dl class="event-examples-list">
545
Supply a callback function to handle the <code>stop</code> event as an init option.
548
<pre><code>$('.selector').slider({
549
stop: function(event, ui) { ... }
555
Bind to the <code>stop</code> event by type: <code>slidestop</code>.
558
<pre><code>$('.selector').bind('slidestop', function(event, ui) {
570
<h2 class="top-header">Methods</h2>
571
<ul class="methods-list">
573
<li class="method" id="method-destroy">
574
<div class="method-header">
575
<h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
577
<dt class="method-signature-label">Signature:</dt>
578
<dd class="method-signature">.slider( 'destroy'
589
<div class="method-description">
590
<p>Remove the slider functionality completely. This will return the element back to its pre-init state.</p>
595
<li class="method" id="method-disable">
596
<div class="method-header">
597
<h3 class="method-name"><a href="#method-disable">disable</a></h3>
599
<dt class="method-signature-label">Signature:</dt>
600
<dd class="method-signature">.slider( 'disable'
611
<div class="method-description">
612
<p>Disable the slider.</p>
617
<li class="method" id="method-enable">
618
<div class="method-header">
619
<h3 class="method-name"><a href="#method-enable">enable</a></h3>
621
<dt class="method-signature-label">Signature:</dt>
622
<dd class="method-signature">.slider( 'enable'
633
<div class="method-description">
634
<p>Enable the slider.</p>
639
<li class="method" id="method-option">
640
<div class="method-header">
641
<h3 class="method-name"><a href="#method-option">option</a></h3>
643
<dt class="method-signature-label">Signature:</dt>
644
<dd class="method-signature">.slider( 'option'
648
, <span class="optional">[</span>value<span class="optional">] </span>
655
<div class="method-description">
656
<p>Get or set any slider option. If no value is specified, will act as a getter.</p>
661
<li class="method" id="method-value">
662
<div class="method-header">
663
<h3 class="method-name"><a href="#method-value">value</a></h3>
665
<dt class="method-signature-label">Signature:</dt>
666
<dd class="method-signature">.slider( 'value'
668
, <span class="optional">[</span>value<span class="optional">] </span>
677
<div class="method-description">
678
<p>Gets or sets the value of the slider. For single handle sliders.</p>
683
<li class="method" id="method-values">
684
<div class="method-header">
685
<h3 class="method-name"><a href="#method-values">values</a></h3>
687
<dt class="method-signature-label">Signature:</dt>
688
<dd class="method-signature">.slider( 'values'
692
, <span class="optional">[</span>value<span class="optional">] </span>
699
<div class="method-description">
700
<p>Gets or sets the values of the slider. For multiple handle or range sliders.</p>
707
<h2 class="top-header">Theming</h2>
708
<p>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.
710
<p>If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.slider.css stylesheet that can be modified. These classes are highlighed in bold below.
713
<h3>Sample markup with jQuery UI CSS Framework classes</h3>
714
<div class="ui-slider<strong> ui-slider-horizontal</strong> ui-widget ui-widget-content ui-corner-all"><br />
715
<a style="left: 0%;" class="<strong>ui-slider-handle</strong> ui-state-default ui-corner-all" href="#"></a><br />
717
<p class="theme-note">
719
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>.
727
Pre-expand include size: 30308 bytes
728
Post-expand include size: 46848 bytes
729
Template argument size: 25336 bytes
730
Maximum: 2097152 bytes
733
<!-- Saved in parser cache with key jqdocs_docs:pcache:idhash:3183-1!1!0!!en!2 and timestamp 20090319021843 -->