Skip to main content

Configuration

Initial value​

Use the value property to set the position of the slider thumb on initialization:

const slider = new dhx.Slider("slider_container", { 
value:20
});

Inverse mode​

In the inverse mode, the slider scale displays values in the reverse order, that is, from the maximal value to the minimal one.

Inverse mode slider with the thumb near the right end showing tooltip value 86 in DHTMLX Suite

To enable this mode, set the inverse property to true:

const slider = new dhx.Slider("slider_container", { 
inverse:true,
min: 100,
max: 0,
step:1
});

Related sample: Slider. Inverse mode of the Slider

Minimal and maximal values​

The minimal and maximal values define the start and end points of the slider. The default values are 0 and 100, respectively. Use the min and max properties to change them:

const slider = new dhx.Slider("slider_container", { 
min:1,
max:150
});

Range mode​

Besides the standard slider with one thumb, you can create a range slider with two thumbs. Set the range property to true and pass an array with the start and end values of the range to the value property:

const slider = new dhx.Slider("slider_container", {
min: 0,
max: 100,
value: 0,
step: 1,
range: true,
value: [25, 75]
});

Related sample: Slider. Range mode of the Slider

For more details, see the Range mode article.

Scale settings​

Use the following properties of the Slider configuration object to configure the look and feel of the scale:

  • tick — (number) sets the interval of steps for rendering the slider scale
  • majorTick — (number) sets the interval for rendering numeric values on the slider scale
  • tickTemplate — (function) sets a template for rendering values on the slider scale

Slider with a scale of ticks and degree labels at 0, 50 and 100 in DHTMLX Suite

const slider = new dhx.Slider("slider_container", { 
tick: 5,
majorTick:10,
tickTemplate: function(major_tick){
return major_tick + "°";
}
});

Related sample: Slider. Custom scale

Related sample: Slider. Slider with a scale

Show only the first and last ticks​

Use the following settings to mark only the minimal and maximal values with ticks:

  • Set the tick property to the value of the max property
  • Set the majorTick property to 1

Slider showing only the first and last ticks labeled 0 and 100 in DHTMLX Suite

const slider = new dhx.Slider("slider_container", { 
max:100, min:0, tick:100, majorTick:1
});

Slider label​

You can show a label next to the slider.

Slider with a Volume label placed to the left of the trackbar in DHTMLX Suite

Use the following properties to set the label and its position:

  • label — specifies the label of a slider
  • labelPosition — defines the position of the label: "left" or "top"
const slider = new dhx.Slider("slider_container", { 
label:"Volume",
// label is rendered on the same level with the trackbar
labelPosition:"left"
});

Related sample: Slider. Label

Step​

The step option defines the size of each jump between values of the slider. The default step is 1. Set a different value in the Slider configuration object:

const slider = new dhx.Slider("slider_container", { 
step:2
});

Tooltip​

A tooltip displays the current value of the slider when the user moves the slider thumb.

Slider showing a tooltip with the value 0 above the dragged thumb in DHTMLX Suite

Use the tooltip property to render the slider value over the thumb:

const slider = new dhx.Slider("slider_container", { 
tooltip:true
});

Related sample: Slider. Tooltip for the Slider

Vertical mode​

The default orientation of the slider scale is horizontal. Set the mode property to "vertical" to arrange the scale vertically:

const slider = new dhx.Slider("slider_container", { 
mode:"vertical"
});

Related sample: Slider. Vertical mode