I'm doing a slider based on noUi Slider. Was trying to achieve so to say "an elegant" solution. Since my ui handle is big I made the ui base slightly bigger with extra values in base. But those values are not allowed and handle will jump back to the allowed values. I decided to put plus and minus buttons to the place where restricted values are.
But the problem is that I can't achieve the effect that when you move the handle on to the control symbols (plus/minus) they would hide behind the handle. In my case they remain on top. And I have trouble resolving this issue.
Some help/advice would be great.
Here's my code (styles are on JSFiddle):
$(document).ready(function(){
var sliders = document.getElementById('red'),
input = document.getElementById('handle'),
sliderPlus = document.getElementById('slider-amount-plus'),
sliderMinus = document.getElementById('slider-amount-minus'),
termCur = 500;
noUiSlider.create(sliders, {
start: termCur,
step: 50,
connect: "lower",
range: {
'min': 0,
'max': 1100
},
pips: {
mode: 'values',
values: [100, 500, 1000],
density: 4.5
}
});
$('<div class="value">' + termCur + ' zł' + '</div>').appendTo($('.noUi-handle', sliders));
sliders.noUiSlider.on('change', function ( values, handle ) {
if ( values[handle] < 100 ) {
sliders.noUiSlider.set(100);
} else if ( values[handle] > 1000 ) {
sliders.noUiSlider.set(1000);
}
});
sliders.noUiSlider.on('update', function( values ) {
termCur = values;
if( termCur >= 100 && termCur <= 1000 ) {
$('.value', sliders).text(parseInt(termCur) + ' zł');}
});
sliderPlus.addEventListener('click', function(){
if(termCur < 1000) {
var setValue = parseInt(termCur) + 50;
sliders.noUiSlider.set(setValue);
}
});
sliderMinus.addEventListener('click', function(){
if(termCur > 100) {
var setValue = parseInt(termCur) - 50;
sliders.noUiSlider.set(setValue);
}
});
<div class="sliders" id="red">
<a class="controls-symbols slider-minus" id="slider-amount-minus"><i class="fa fa-minus"></i></a>
<a class="controls-symbols slider-plus" id="slider-amount-plus"><i class="fa fa-plus"></i></a>
</div>
on
method like this:$(document).on('click', sliderMinus, function(e){ alert('click'); });
This will make sure the event is always attached. Before the references to thesliderMinus
was cloned then removed so the event wasn't getting properly – Oxval>=100 && val<= 1000
is instead ofval>100 && val< 1000
then on.(click) breaks. I had to put$('.value', sliders).text(termCur + ' zł');
into click events and it works now. Fiddle – Nickelousval>=100 && val<= 1000
break on.click event? The fix that I did isn't ideal because I need the update event to work with 100 and 1000 as well so the value would get properly updated when I slide the handle but currently it stops on 150 or 950. – Nickelous