Examples

Basic style customization

You are free to customize the range slider as much as you wish, using only CSS.

The width (for horizontal) or height (for vertical) of the slider, depends on the container in which it's placed and take 100%.

Play around with the background-color of .range-bar and .range-quantity, add a background-image to .range-handle, add some nice background-image to .range-min and .range-max, get use of the hideRange option and you may end up with something as fun as this:

The sky is the limit.

Hint: Use the klass option to add an additional class to the slider and apply different style to it

Minimum, maximum and start values

Changing your default min, max and start values is pretty easy. The start value has to be a number in your min-max interval, otherwise it takes the value of either min or max, depending on which is closer. Negative values are supported as well.

            
var init = new Powerange(elem, { min: 16, max: 256, start: 128 });

Decimal

Display decimal number with 2 characters after the decimal point.

            
var init = new Powerange(elem, { decimal: true });

Slider step

You can change the step with which the handle moves, using the step option.

            
var init = new Powerange(elem, { step: 10 });

Hide range values

You can hide the min and max values, by using the hideRange option.

            
var init = new Powerange(elem, { hideRange: true });

Disabled

Disable the range slider and change it's default disabledOpacity if needeed.

            
var init = new Powerange(elem, { disable: true, disabledOpacity: 0.75 });

Horizontal and vertical slider

The default Powerange slider is horizontal. However, you can make it vertical, by setting vertical: true.

            
var init = new Powerange(elem, { vertical: true });

Checking state

Check the current value of the range slider, by looking at the value of the text input element.

On click:

            
var clickInput = document.querySelector('.js-check-click')
  , clickButton = document.querySelector('.js-check-click-button')

clickButton.addEventListener('click', function() {
  alert(clickInput.value);
});

On change:

            
var changeInput = document.querySelector('.js-check-change');

changeInput.onchange = function() {
  document.getElementById('js-display-change').innerHTML = changeInput.value;
};

Callback

The callback function is invoked on slider initialization and on slider handle movement. It's very appropriate for displaying the current value in another element.

            
var elem = document.querySelector('.js-range');
var init = new Powerange(elem);

function displayValue() {
  document.getElementById('display-box').innerHTML = elem.value;
}

Interacting with another elements

Just a simple example of how you can interact with an element, when changing the slider value. In this case, we change the opacity of an awesome power ranger mask.

            
var elem = document.querySelector('.js-range');
var init = new Powerange(elem, { callback: setOpacity, decimal: true, min: 0, max: 1, start: 1 });

function setOpacity() {
  document.querySelector('.js-change-opacity').style.opacity = elem.value;
}

适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.

来源:站长素材