Range Slider
Single range slider layout is pretty simple:
Dual range slider is more simpler as it doesn’t require input element because input:range doesn’t support dual range:
<div class="range-slider"></div>
Range Slider Colors
Range Slider supports all . So to change its color just add color-[color] class to range slider element.
<!-- red range -->
<div class="range-slider color-red">...</div>
<!-- orange range -->
<div class="range-slider color-orange">...</div>
Let’s look at related App methods to work with Range Slider:
app.range.create(parameters)- create Range Slider instance
- parameters - object. Object with range slider parameters
Method returns created Range Slider’s instance
app.range.destroy(el)- destroy Range Slider instance
- el - HTMLElement or string (with CSS Selector) or object. Range Slider element or Range Slider instance to destroy.
- el - HTMLElement or string (with CSS Selector). Range Slider element.
Method returns Range Slider’s instance
app.range.getValue(el)- get Range Slider value
- el - HTMLElement or string (with CSS Selector). Range Slider element.
Method returns range slider value
app.range.setValue(el, value)- set new Range Slider value
- el - HTMLElement or string (with CSS Selector). Range Slider element.
- value - number (in case of single range) or array of values (in case of dual range)
Method returns Range Slider’s instance
Range Slider Parameters
Now let’s look at list of available parameters we need to create Range Slider:
So to create Range Slider we have to call:
Range Slider Events
Range Slider will fire the following DOM events on range element and events on app and range instance:
Range Slider instance emits events on both self instance and app instance. App instance events has same names prefixed with range
.
If you don’t need to use Range Slider API and your Range Slider is inside of the page and presented in DOM on moment of page initialization then it can be auto initialized with just adding additional range-slider-init
class:
<!-- Add range-slider-init class -->
<input type="range" min="0" max="100" step="1" value="10">
</div>
In this case if you need to access created Range Slider instance you can use the app.range.get
app method:
var range = app.range.get('.range-slider');
if (range.value > 50) {
// do something
}
When using auto init you may need to pass additional parameters. It can be done with two ways:
In you case you use single-range slider and you have input:range inside, then
step
,min
,max
, parameters can be set from same input attributes:<!-- min, max, step, value parameters will be set for same input attributes -->
<div class="range-slider range-slider-init">
<input type="range" min="0" max="100" step="1" value="10">
</div>
Otherwise, if you don’t have input:range inside or you use dual range input you can set all available parameters via
data-
attributes on range slider element.<!-- parameters set via data- attributes -->
<div
class="range-slider range-slider-init"
data-dual="true"
data-min="0"
data-max="100"
data-step="10"
data-label="true"
data-value-left="30"
data-value-right="60"
></div>
Examples
<div class="block-title">Volume</div>
<div class="list simple-list">
<ul>
<li>
<div class="item-cell width-auto flex-shrink-0">
<i class="icon f7-icons ios-only">volume_mute_fill</i>
<i class="icon material-icons md-only">volume_mute</i>
</div>
<div class="item-cell flex-shrink-3">
<!-- range slider -->
<input type="range" min="0" max="100" step="1" value="10">
</div>
<div class="item-cell width-auto flex-shrink-0">
<i class="icon f7-icons ios-only">volume_fill</i>
<i class="icon material-icons md-only">volume_up</i>
</div>
</li>
</ul>
</div>
<div class="block-title">Brightness</div>
<div class="list simple-list">
<ul>
<li>
<div class="item-cell width-auto flex-shrink-0">
<i class="icon f7-icons ios-only">circle</i>
<i class="icon material-icons md-only">brightness_low</i>
</div>
<div class="item-cell flex-shrink-3">
<!-- range slider, enable labels -->
<div class="range-slider range-slider-init color-orange" data-label="true">
<input type="range" min="0" max="100" step="1" value="50">
</div>
</div>
<div class="item-cell width-auto flex-shrink-0">
<i class="icon f7-icons ios-only">circle_half</i>
<i class="icon material-icons md-only">brightness_high</i>
</div>
</li>
</ul>
</div>
Handle price change:
$$('#price-filter').on('range:change', function (e, range) {
$$('.price-value').text('$'+(range.value[0])+' - $'+(range.value[1]));
});