Philipp Chapkovski
Philipp Chapkovski

Reputation: 2059

change color of ion range-slider handle

If I try to change the default color of ion range-slider (available here: https://github.com/IonDen/ion.rangeSlider) from red (default) to blue, like that:

.irs-slider.single {
    background: blue;
}

It becomes square:

enter image description here

(originally it looks like a thin red line: enter image description here)

What am I doing wrong?

DEMO

https://jsfiddle.net/chapkovski/xpvt214o/995048/

$(".js-range-slider").ionRangeSlider({
        type: "single",
        min: 0,
        max: 1000,
        from: 200,
        to: 500,
        grid: true
    });
.irs-slider.single {
    background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/js/ion.rangeSlider.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.skinFlat.css">
<input type="text" class="js-range-slider" name="my_range" value="" />

Upvotes: 2

Views: 9952

Answers (5)

Manthan Patel
Manthan Patel

Reputation: 1852

Below snippet for change whole ion range slider color to any color

$(".js-range-slider").ionRangeSlider({
  type: "single",
  min: 0,
  max: 1000,
  from: 200,
  to: 500,
  grid: true
});
    .irs--flat .irs-handle>i:first-child {
    background-color: #4e73df!important;//Replace With Your color code
}
.irs--flat .irs-bar {
    background-color: #4e73df!important;//Replace With Your color code
}
.irs--flat .irs-from, .irs--flat .irs-to, .irs--flat .irs-single {
    background-color: #4e73df!important;//Replace With Your color code
}
.irs--flat .irs-from:before, .irs--flat .irs-to:before, .irs--flat .irs-single:before {
    border-top-color: #4e73df!important;//Replace With Your color code
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.3.0/css/ion.rangeSlider.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.3.0/js/ion.rangeSlider.min.js"></script>
<input type="text" class="js-range-slider" name="my_range" value="" />

Upvotes: 6

Satria Ikhsan
Satria Ikhsan

Reputation: 44

i change with js script like this, i hope you will use it

onChange: function(data) {
let id = $(data.slider[0]['parentNode']).attr('id');

if (data.from < 50) {
  $('#' + id).find('.irs-bar--single').css('background-color', '#ee22fa');
  $('#' + id).find('.irs-single').css('background-color', '#ee22fa');
  $('#' + id).find('.irs-handle > i:first-child').css('background-color', '#ee22fa');
} else if (data.from <= 60) {
  $('#' + id).find('.irs-bar--single').css('background-color', '#ed5565');
  $('#' + id).find('.irs-single').css('background-color', '#ed5565');
  $('#' + id).find('.irs-handle > i:first-child').css('background-color', '#ed5565');
}
}

https://jsfiddle.net/satria08/v9u0jyt6/

Upvotes: 1

suraj khot
suraj khot

Reputation: 61

$('#traffic_percent').ionRangeSlider({
  min: 0,
  max: 100,
  type: 'single',
  prefix: "%",
  from: $('#traffic_percent').val(),
  onChange: function(data) {
    var color = $('#traffic_percent').val();

    if (color > 50) {
      $('#your div id').find(".irs-bar").css("background", "#6fda43");
    } else {
      $('#your div id').find(".irs-bar").css("background", "#fb8c8a");
    }
  }
});

Upvotes: 0

Temani Afif
Temani Afif

Reputation: 272589

The background is an image (https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/img/sprite-skin-flat.png), so you cannot simply change the color. You can consider a gradient to create a similar image with the color you want. Since it's a simple line it should be easy.

$(".js-range-slider").ionRangeSlider({
  type: "single",
  min: 0,
  max: 1000,
  from: 200,
  to: 500,
  grid: true
});
.irs-slider.single {
  background: linear-gradient(blue, blue) center/2px 100% no-repeat;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/js/ion.rangeSlider.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.skinFlat.css">
<input type="text" class="js-range-slider" name="my_range" value="" />

Upvotes: 0

Cl&#233;ment Baconnier
Cl&#233;ment Baconnier

Reputation: 6058

Looking at the demo,the .single class is used in the tooltip element. However I can change the thin red color to blue like this:

.irs--flat .irs-handle>i:first-child {
    background: blue;
}

Upvotes: 0

Related Questions