diff --git a/documentation/examples-content/click-pips.php b/documentation/examples-content/click-pips.php new file mode 100644 index 00000000..83196301 --- /dev/null +++ b/documentation/examples-content/click-pips.php @@ -0,0 +1,28 @@ + +
Issue #733 asks about clicking pips to move the slider to their value. noUiSlider 11 adds a data-value
attribute to all .noUi-value
elements that makes this easy.
noUiSlider's connect elements can be individually colored or otherwise styled.
+ +We'll initialize all sliders with the same options, and use the slide
callback to keep to color in sync with the slider values. This callback fires when the slider is moved by sliding, or when it is clicked or tapped.
<div id="colorpicker">
+ <div class="sliders" id="red"></div>
+ <div class="sliders" id="green"></div>
+ <div class="sliders" id="blue"></div>
+
+ <div class="result"></div>
+</div>
+
+ setColor
functionAs all dates in JavaScript can be represented as time, noUiSlider can handle them, too. This example will show you how to convert dates to numerical ranges, and then use the update
event to display them in a pretty format.
We'll be creating timestamps from strings. In order to do this easily, we'll define a new helper function. This function accepts a string, creates a new Date
and then returns it as a timestamp.
In in overview below you'll find the code used to run this example. For readability, all helper functions have been moved into their own tab.
+ +The nth
function was borrowed from this StackOverflow question.
Issue #836 requested a way to toggle tooltips after slider creation. This effect can be achieved by using the .noUi-active
class to show and hide the tooltips. No additional JavaScript is involved.
noUiSlider's 'update'
method is useful for synchronizing with other elements, such as <input>
(type="number"
) and <select>
.
<option>
elements<select>
and <input>
If you are working with arbitrarily large numbers, you should not use these directly in noUiSlider, as you'll run into some JavaScript limitations. Instead, you should map your values to an array
.
Numbers is JavaScript are Double Precision Floats, which can store numbers up to 2^53 (9007199254740992) precisely. For reference, see this StackOverflow question, or issue #427 filed on GitHub.
+ +As an example, see the 'range'
option for a RAM selector offering 14 steps from 512MB to 8GB. The 'step'
are ommited for clarity. The values are provided as bytes. A better solution would be to abstract the byte values away from the slider, looking up the byte values in an array. This keeps the slider configuration simple and prevents issues with floating point precision.
(These values fit within the limit just fine, but demonstrate the point really well!)
+ +Much like the keypress example, handles can be made keyboard-focusable.
+ +keypress
on the handleTo keep the library small, features like keyboard interaction haven't been included. However, adding features to input fields linked to a slider is easy. noUiSlider provides API's to help you. In this example, pressing the keyboard arrow keys will increase/decrease the slider by one step.
+ +This example uses the 'step'
API to determine by how much the slider should be changed. You don't need this function if your slider is linear. In that case, increase/decrease the value with the ammount of your step
.
We'll listen to keydown on the '#input-with-keypress'
element, and pass the event to a function so we can read the code that identifies the key.
Note that the slider value will be a string
, so we'll need to parse it to an integer.
keypress
on the inputTwo cross-updating sliders can be created using a combination of the change
and slide
events.
Crossupdate
functionOne of noUiSlider's core features is the ability to divide the range in a non-linear fashion. Stepping can be applied. The example on the right shows where the handles are on the slider range in values and percentages.
+ +When using a stepped slider, your configuration may require that certain steps aren't available. Using the snap
feature, this effect can be created.
Notice how 40
and 80
can't be selected on the slider.
If you want to disable the edges of a slider, the set event can be used to reset the value if a limit is passed. Note how the handle 'bounces back' when it is released below 20
or above 80
. noUiSlider also supports disabling edges altogether, which can be done using the padding option.
change
eventMany application interfaces have options that can be turned on or off using switches. noUiSlider is well suited for this, especially because of the wide touch support.
+ +The update
event can be used to keep track of changes to the handle. We'll set the range to [0, 1]
, which leaves one step of 1
.
We'll initialize all sliders with the same options, and use the slide
callback to keep to color in sync with the slider values. This callback fires when the slider is moved by sliding, or when it is clicked or tapped.
<div id="colorpicker">
- <div class="sliders" id="red"></div>
- <div class="sliders" id="green"></div>
- <div class="sliders" id="blue"></div>
-
- <div class="result"></div>
-</div>
-
- setColor
functionnoUiSlider's 'update'
method is useful for synchronizing with other elements, such as <input>
(type="number"
) and <select>
.
<option>
elements<select>
and <input>
One of noUiSlider's core features is the ability to divide the range in a non-linear fashion. Stepping can be applied. The example on the right shows where the handles are on the slider range in values and percentages.
- -Two cross-updating sliders can be created using a combination of the change
and slide
events.
Crossupdate
functionIssue #733 asks about clicking pips to move the slider to their value. noUiSlider 11 adds a data-value
attribute to all .noUi-value
elements that makes this easy.
Issue #836 requested a way to toggle tooltips after slider creation. This effect can be achieved by using the .noUi-active
class to show and hide the tooltips. No additional JavaScript is involved.
noUiSlider's connect elements can be individually colored or otherwise styled.
- -To keep the library small, features like keyboard interaction haven't been included. However, adding features to input fields linked to a slider is easy. noUiSlider provides API's to help you. In this example, pressing the keyboard arrow keys will increase/decrease the slider by one step.
- -This example uses the 'step'
API to determine by how much the slider should be changed. You don't need this function if your slider is linear. In that case, increase/decrease the value with the ammount of your step
.
We'll listen to keydown on the '#input-with-keypress'
element, and pass the event to a function so we can read the code that identifies the key.
Note that the slider value will be a string
, so we'll need to parse it to an integer.
keypress
on the inputWhen using a stepped slider, your configuration may require that certain steps aren't available. Using the snap
feature, this effect can be created.
Notice how 40
and 80
can't be selected on the slider.
If you are working with arbitrarily large numbers, you should not use these directly in noUiSlider, as you'll run into some JavaScript limitations. Instead, you should map your values to an array
.
Numbers is JavaScript are Double Precision Floats, which can store numbers up to 2^53 (9007199254740992) precisely. For reference, see this StackOverflow question, or issue #427 filed on GitHub.
- -As an example, see the 'range'
option for a RAM selector offering 14 steps from 512MB to 8GB. The 'step'
are ommited for clarity. The values are provided as bytes. A better solution would be to abstract the byte values away from the slider, looking up the byte values in an array. This keeps the slider configuration simple and prevents issues with floating point precision.
(These values fit within the limit just fine, but demonstrate the point really well!)
- -Much like the keypress example, handles can be made keyboard-focusable.
- -keypress
on the handleAs all dates in JavaScript can be represented as time, noUiSlider can handle them, too. This example will show you how to convert dates to numerical ranges, and then use the update
event to display them in a pretty format.
We'll be creating timestamps from strings. In order to do this easily, we'll define a new helper function. This function accepts a string, creates a new Date
and then returns it as a timestamp.
In in overview below you'll find the code used to run this example. For readability, all helper functions have been moved into their own tab.
- -The nth
function was borrowed from this StackOverflow question.
Many application interfaces have options that can be turned on or off using switches. noUiSlider is well suited for this, especially because of the wide touch support.
- -The update
event can be used to keep track of changes to the handle. We'll set the range to [0, 1]
, which leaves one step of 1
.
If you want to disable the edges of a slider, the set event can be used to reset the value if a limit is passed. Note how the handle 'bounces back' when it is released below 20
or above 80
. noUiSlider also supports disabling edges altogether, which can be done using the padding option.
change
event