Slider
A range slider widget wrapping the native <input type="range">. It lets users select a numeric value by dragging a thumb along a track. Configure the range with min, max, and step. The current value can be displayed in the label, the thumb, or in a tooltip. Optional step markers can be shown along the track using showSteps.
const slider = new Slider({
text : 'Opacity',
min : 0,
max : 100,
step : 10,
value : 50,
showValue : true,
appendTo : document.body
});
// Listen for value changes
slider.on('input', ({ value }) => {
console.log('New value:', value);
});
Useful configs, properties, and events
| Config / Event | Description |
|---|---|
| min | Minimum value (default 0) |
| max | Maximum value (default 100) |
| step | Step increment between values |
| value | Current slider value |
| text | Label text; appends current value if showValue is true |
| showValue | Show value in label (true) or in the thumb ('thumb') |
| showTooltip | Show the current value in a tooltip on hover/drag |
| showSteps | Show tick marks at each step interval |
| input | Fired on each value change as the thumb is dragged |
| change | Fired when the value changes after the thumb is released |
See also
- NumberField - A numeric input field for typed values
- Widget - Base class for all widgets
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Maximum value
Has a corresponding runtime max property.
-
Minimum value
Has a corresponding runtime min property.
-
Show the step markers
-
Show the slider value in a tooltip
-
Show value in internal label (specify
true), or in the thumb (specify 'thumb'). -
Step size
Has a corresponding runtime step property.
-
Text for the sliders internal label. Appends value if
showValueistrueHas a corresponding runtime text property.
-
Icon to show in the thumb. By default, no icon is shown.
Has a corresponding runtime thumbIcon property.
-
A config object for the tooltip to show while hovering the slider.
-
Unit to display next to the value, when configured with
showValue : trueHas a corresponding runtime unit property.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Slider class, or subclass thereof.
-
Get input element.
-
Maximum value
Has a corresponding max config.
-
Minimum value
Has a corresponding min config.
-
Step size
Has a corresponding step config.
-
Text for the sliders internal label. Appends value if
showValueistrueHas a corresponding text config.
-
Icon to show in the thumb. By default, no icon is shown.
Has a corresponding thumbIcon config.
-
Unit to display next to the value, when configured with
showValue : trueHas a corresponding unit config.
-
Identifies an object as an instance of Slider class, or subclass thereof.