forked from leongersen/noUiSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider-read-write.php
96 lines (61 loc) · 2.67 KB
/
slider-read-write.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
$title = "noUiSlider - Getting and setting slider values";
$description = "Reading and setting values from a slider is as easy as reading from any other form element.";
$canonical = "nouislider/slider-read-write/"
?>
<h1>Getting and setting slider values</h1>
<?php sect('reading'); ?>
<h2>Reading slider values</h2>
<section>
<div class="view">
<p>noUiSlider has an API with two simple methods: <code>.get()</code> and <code>.set()</code>. To get the current slider value:</p>
<?php code('read'); ?>
<p>For one-handle sliders, calling <code>.get()</code> will return the value as a <code>'string'</code>. For multi-handle sliders, an <code>array['string', 'string', ...]</code> will be returned.</p>
</div>
</section>
<?php sect('setting'); ?>
<h2>Setting slider values</h2>
<section>
<div class="view">
<p>If you have configured the slider to use one handle, you can change the current value by passing a number to the <code>.set()</code> method.</p>
<p>For sliders with multiple handles, pass an array. One-handled sliders will also accept arrays.</p>
<p>Within an array, you can set any position to <code>null</code> to you leave a handle unchanged.</p>
<p>noUiSlider will always limit values to the slider range.</p>
<p>To set a single slider handle, the <code>setHandle</code> method can be used. This method accepts a zero-indexed handle number, a value and optionally a 'fire set event' boolean.</p>
<p>Passing <code>null</code> as the value to <code>setHandle</code> will leave the handle unchanged.</p>
<p>To return to the initial slider values, you can use the <code>.reset()</code> method. This will <strong>only</strong> reset the slider <i>values</i>.</p>
</div>
<div class="side">
<?php code('write'); ?>
</div>
</section>
<?php sect('example'); ?>
<h2>Example</h2>
<section>
<div class="view">
<p>Clicking the button below sets the slider, which uses a <code>range</code> from <code>0</code> to <code>100</code>, to <code>20</code>.</p>
<div class="example">
<div id="slider"></div>
<div class="logger">
<button id="write-button">Set to 20</button>
<button id="read-button">Read slider value</button>
</div>
<?php run('set', false); ?>
<?php run('buttons', false); ?>
</div>
</div>
<div class="side">
<?php code('set'); ?>
<div class="viewer-header">Handling button presses</div>
<div class="viewer-content">
<?php code('buttons'); ?>
</div>
</div>
</section>
<?php sect('formatting'); ?>
<h2>Number formatting</h2>
<section>
<div class="view">
<p>See <a href="/nouislider/number-formatting/">the documentation on number formatting</a>.</p>
</div>
</section>