Reputation: 1380
I have been working with application where I have integrated noUiSlider. I have already integrated it and working well with step of 15 minutes for time based slider with range of 24 hours as below.
$(".time_range_slider").noUiSlider({
start : [8, 18],
behaviour : 'drag',
connect : true,
step : .25,
range : {'min': 0, 'max': 24}
});
$(".time_range_slider").noUiSlider_pips({
mode : 'steps',
filter : filter_hour,
stepped : true
});
function filter_hour(value, type) {
return ((value * 100) % 100 == 0) ? 1 : 0;
}
But now i want to make step of 10 minutes. I have tried many aspects like step: .16 but not able to achieve expected result.
Please suggest any solution for same
Upvotes: 4
Views: 3359
Reputation: 4902
My answer isn't using jquery case I don't know why noUiSlider isn't detected from jquery inside snippet, hope you can deal with that.
How is implemented:
use minutes range for selection:
range : {'min': 0, 'max': 1440}
format pipes labels and selector tooltips, using wNumb.js to show format hh:mm
snippet:
var range = document.getElementById('time_range_slider');
range.style.height = '800px';
range.style.margin = '0 auto 30px';
var aproximateHour = function (mins)
{
//http://greweb.me/2013/01/be-careful-with-js-numbers/
var minutes = Math.round(mins % 60);
if (minutes == 60 || minutes == 0)
{
return mins / 60;
}
return Math.trunc (mins / 60) + minutes / 100;
}
noUiSlider.create(range, {
start : [240, 1080],
connect: true,
direction: 'rtl',
orientation: 'vertical',
behaviour: 'tap-drag',
step: 10,
tooltips: true,
range : {'min': 0, 'max': 1440},
format: wNumb({
decimals: 2,
mark: ":",
encoder: function(a){
return aproximateHour(a);
}
}),
pips: {
mode : 'steps',
format: wNumb({
mark: ":",
decimals: 2,
encoder: function(a ){
return aproximateHour(a);
}
}),
filter : filter_hour,
stepped : true,
density:1
}
});
function filter_hour(value, type) {
return (value % 60 == 0) ? 1 : 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/wnumb/1.0.4/wNumb.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/9.1.0/nouislider.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/9.1.0/nouislider.js"></script>
<div id="time_range_slider"></div>
Upvotes: 9