Slider

live example

Explore the API in the live example.

api reference

Slider(name[, parent])
The slider control widget. Inherits all API from the [Widget] ../components/widget.html component. The slider is constrained to a rectangle defined by the width/height and the margins. It is vertically centered. The scale ticks are implemented using BottomAxis , making all the API for that component available for the slider.

Parameters

NameTypeDescription
namestringName of the widget. Should be a unique identifier.
parentstringoptionalSee [Widget] ../components/widget.html for description. Default value is body.
Slider.callback([callback])
Binds a callback to the slider. Note that this is called every time the handle is dragged (you may want to debounce it).

Parameters

NameTypeDescription
callbackFunctionoptionalCallback to bind when the handle is dragged. The current value is passed as parameter. Default value is null.

Returns

Slider
Reference to the Slider API.

Examples

// Print current value to console.
const slider = dalian.Slider('my-control')
  .callback(console.log)
  .render()

// Remove callback.
slider.callback()
  .render()
Slider.color([color])
Sets the color of the active handle and value track of the slider.

Parameters

NameTypeDescription
colorstringoptionalColor to set. Default value is grey.

Returns

Slider
Reference to the Slider API.

Examples

// Set slider color.
const slider = dalian.Slider('my-control')
  .color('royalblue')
  .render()

// Reset color to default.
slider.color()
  .render()
Slider.max([value])
Sets the maximum of the slider.

Parameters

NameTypeDescription
valuenumberoptionalMaximum value to set. Default value is 1.

Returns

Slider
Reference to the Slider API.

Examples

// Set the maximum value.
const slider = dalian.Slider('my-control')
  .max(2)
  .render()

// Reset max to 1.
slider.max()
  .render()
Slider.min([value])
Sets the minimum value of the slider.

Parameters

NameTypeDescription
valuenumberoptionalMinimum value to set. Default value is 0.

Returns

Slider
Reference to the Slider API.

Examples

// Set the minimum value.
const slider = dalian.Slider('my-control')
  .min(-3)
  .render()

// Reset min to 0.
slider.min()
  .render()
Slider.step([value])
Sets the step size for the slider. If it is set to 0, the slider can take continuous values.

Parameters

NameTypeDescription
valuenumberoptionalStep size to set. Only the absolute value of the provided number is considered. Default value is 0.

Returns

Slider
Reference to the Slider API.

Examples

// Set step size to 0.1.
const slider = dalian.Slider('my-control')
  .step(0.1)
  .render()

// Reset step size to 0.
slider.step()
  .render()
Slider.thickness([thickness])
Sets the slider thickness in pixels.

Parameters

NameTypeDescription
thicknessnumberoptionalThickness to set. Default value is 8.

Returns

Slider
Reference to the Slider API.

Examples

// Set thickness to 10px.
const slider = dalian.Slider('my-control')
  .thickness(10)
  .render()

// Reset thickness to default.
slider.thickness()
  .render()
Slider.trackColor([color])
Sets the slider's track color.

Parameters

NameTypeDescription
colorstringoptionalColor to set. Default value is #ddd.

Returns

Slider
Reference to the Slider API.

Examples

// Set track color to white.
const slider = dalian.Slider('my-control')
  .trackColor('#fff')
  .render()

// Reset track color.
slider.trackColor()
  .render()
Slider.value([value])
Sets the slider's value. Note that this method does not invoke the callback, merely positions the handle.

Parameters

NameTypeDescription
valuenumberoptionalValue to set handle to. If it is not specified, no change is taking place. Default value is 0.

Returns

Slider
Reference to the Slider API.

Examples

// Set value to 0.7.
const slider = dalian.Slider('my-control')
  .value(0.7)
  .render()