I'm working with bootstrap-slider and want to make the slider when being dragged , and have their value between certain number range (I use onChange
), modify the background color of the selection bar. I've been able to do the border modification, but the selection bar itself I could not find a shape with jQuery
.
The code:
$(document).ready(function() {
$("#ex13").slider({
id: "slider12a",
min: 0,
max: 100,
ticks: [0, 25, 50, 75, 100],
ticks_snap_bounds: 5,
ticks_labels: ['', '', '', '', ''],
value: 0
});
});
function setarCorSlider(tamanho) {
if (tamanho < 24) {
document.getElementById('slider12a').style.background = "red"; //altera a borda, mas pelo meu entendimento se eu apelidei o slider 'ex13' de id: 'slider12a', deveria alterar tudo e não apenas a borda
//tentei usar jQuery para alterar a cor da classe slider-selection, mas não funcionou
$(document).ready(function() {
$('.slider-selection').css('background: red');
});
//ou
$('.slider-selection').css('background: red'); //também testei assim e não funcionou
} else if (tamanho > 25 && tamanho < 74) {
document.getElementById('slider12a').style.background = "yellow";
} else if (tamanho > 75) {
document.getElementById('slider12a').style.background = "green";
}
}
#slider12a .slider-selection {
background: #DDD; //*Inicialmente a barra possui o background da barra azul, a medida que vai arrastando ela*
}
<link href="http://seiyria.com/bootstrap-slider/css/bootstrap-slider.css" rel="stylesheet" />
<link href="http://seiyria.com/bootstrap-slider/dependencies/css/bootstrap.min.css" rel="stylesheet" />
<script type='text/javascript' src="http://seiyria.com/bootstrap-slider/dependencies/js/modernizr.js"/><inputid="ex13" type="text" data-slider-ticks="[0, 25, 50, 75, 100]" data-slider-ticks-snap-bounds="5" onchange="setarCorSlider(this.value)" />
<script type='text/javascript' src="http://seiyria.com/bootstrap-slider/dependencies/js/jquery.min.js"/><scripttype='text/javascript'src="http://seiyria.com/bootstrap-slider/js/bootstrap-slider.js" />
<!-- coloquem o JavaScript do código aqui -->