Here's an example of a jQuery UI slider with a range of 1 to 5, with values displayed and a single selector starting from zero:

HTML:

<div class='slider'></div>
<div class='slider-value'></div>

CSS:

.slider {
  direction: rtl;
  margin: 20px 0;
}

JavaScript:

$(function() {
  var values = [0, 1, 2, 3, 4, 5];
  var slider = $('.slider');
  var sliderValue = $('.slider-value');

  slider.slider({
    range: 'min',
    min: 0,
    max: 5,
    value: 0,
    slide: function(event, ui) {
      sliderValue.text(values[ui.value]);
    }
  });

  sliderValue.text(values[slider.slider('value')]);
});

The direction: rtl CSS property sets the direction of the slider to right-to-left. The values array contains the values that correspond to each slider position. The slider variable selects the slider element, and the sliderValue variable selects the element where the value will be displayed.

The slider function initializes the slider with the specified options, including range: 'min' to create a single handle, min: 0 and max: 5 to set the range of the slider, value: 0 to set the starting value, and slide to update the value displayed when the slider is moved.

The sliderValue.text function sets the value displayed to the corresponding value in the values array based on the current slider position. Finally, the sliderValue.text(values[slider.slider('value')]) line sets the initial value displayed to the starting value of the slider.

jQuery UI Slider with RTL Direction, Range 1 to 5, and Value Display

原文地址: https://www.cveoy.top/t/topic/neIO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录