lt-slider

Minimal JS slider with live value display and mapped ranges (no external CSS required)

Demo

Brightness Control

Display Value: 50

Actual Value: 0.00

Installation

Include the script before the closing </body> tag, or in your build system:

<script src="https://ui.likethat.studio/slider/lt_slider.js"></script>

Basic Usage

Turn any <input type="range"> into an enhanced slider.

<input type="range" class="tl-slider" value="30" data-min="0" data-max="100" />

<script>
// After loading lt_slider.js
attachSlider('.tl-slider', {
  min: 0,
  max: 100,
  onInput: (value, slider) => {
    console.log('Actual:', value);
  }
});
</script>

Configuration Options

OptionTypeDefaultDescription
minnumberundefinedMinimum actual value.
maxnumberundefinedMaximum actual value.
displayMinnumberundefinedMinimum display thumb position.
displayMaxnumberundefinedMaximum display thumb position.
onInputfunctionundefinedCallback: (actualValue, sliderElement) fires on every slide.
labelstring|falseundefinedThumb label text; false to disable.
showValuebooleantrueShow live display value next to track.
labelClassstring''Extra CSS class for label.
valueClassstring''Extra CSS class for value element.
debugbooleanfalseEnable debug logs in console.

Live Properties & Methods

Every enhanced slider gains these on its element:

NameTypeDescription
slider.displayValuenumberCurrent thumb position as display range.
slider.actualValuenumberMapped value in [min, max] range.
slider.getCurrentDisplayValue()functionReturns displayValue.
slider.getCurrentValue()functionReturns actualValue.
slider.setDisplayValue(value)functionProgrammatically jump to a display position, updates actual.
slider.setActualValue(value)functionProgrammatically set actual: reverse-maps to display.

API Reference

attachSlider(selector, options)

Initialize all matching range inputs.

Example with Programmatic Control

<input id="vol" type="range" class="tl-slider" value="25" />
<script>
attachSlider('#vol', { min: 0, max: 1, displayMin: 0, displayMax: 100 });
const slider = document.getElementById('vol');
// Move to display 75:
slider.setDisplayValue(75);
// Log actual:
console.log(slider.actualValue);
</script>

Events

Use the onInput callback—this is the only notification mechanism; no extra DOM events are emitted.

attachSlider('.tl-slider', {
  onInput: (val, el) => console.log('Slider moved to', val)
});