But this is kind of useless! Unless you just want a pretty UI toy to play with!
Because once rendered to the page, there’s no feedback upon interaction.
Binding the values
Typically we would want to be able to use the value of the Slider in our application. This
could either be to change another part of the interface in a Rich Internet Application, or to
send the value to a server as part of a Form.
So here we will bind the value prop to a value variable and bind the <input> element to the same variable.
<script>import RangeSlider from'svelte-range-slider-pips';let value =10;</script><RangeSlidermin={0} max={100} bind:value /><inputtype="number"bind:value />
<scriptdefersrc="svelte-range-slider-pips.min.js"></script><divid="binding-slider"></div><inputtype="number"id="binding-input"value="10" /><scriptdefer>let value =10;constslider=newRangeSlider({ target: document.querySelector("#binding-slider"), props: { min: 0, max: 100, value: value } });constinput= document.querySelector("#binding-input"); slider.$on('change', (e) => { value = e.detail.value; input.value = value; }); input.addEventListener('change', (e) => { value = e.target.valueAsNumber; slider.$set({ value: value }); });</script>
The most common use case is to allow a user to select a value
from a range of values. Using the special feature of pips to render
beside the Slider to hint at the progress. It’s also common to show a float value
above the handle to help the user see the exact value they are selecting.
Here; we are binding the values[] prop to a values variable so that the Slider’s value can be
used elsewhere in our application.