Ion.RangeSlider 2.0.3
Asked Answered
H

2

6

I’m trying to using Ion.RangeSlider 2.0.3

URL : http://ionden.com/a/plugins/ion.rangeSlider/demo_advanced.html

So I want to modify that slider with three colors. Left, Middle, Right likewise. I have attached this image for get idea what I want to need.

enter image description here

So i need your help to customize this slider.

Thanks.

Heroics answered 6/2, 2015 at 8:56 Comment(0)
Y
9

I did the similar thing. Here is the related css and javascript code segments to achieve it. Let say I want left side green, mid yellow and right side red, then

CSS

.irs-line-left {
  background: #66b032;
  width: 60%;
}

.irs-line-mid {
  background: #FFBF00;
}

.irs-line-mid:before {
  content: '';
  background-color: #FF0000;
  position: absolute;
  left: 54%;
  top: 0;
  right: 0;
  bottom: 0;
}

.budget-page .irs-line-right {
  background: #FF0000;
  width: 40%;
}

.budget-page .irs-line-mid {
  width: 0 !important;
}

.irs-bar { 
  background: #FFBF00;
}

Now here is the trick. When you change the two points we need to change the left and right side width to change the color width dynamically.

Javascript section.

var iri_line_left = $(".irs-line-left");
var iri_line_right = $(".irs-line-right");

 $("#color-slider").ionRangeSlider({
        type: "double",
        min: 0,
        max: 100,
        from: 60,
        to: 80,
        grid: true,
        onChange: function (data) {
            var leftWidth = Math.ceil(data.from_percent);
            var rightWidth = 100 - leftWidth;

            // set left side width
            iri_line_left.css({ 'width': leftWidth + "%" }); 

            // set right side width
            iri_line_right.css({ 'width': rightWidth + "%" }); 

        }
    });

Hope this will help you.

Yarber answered 16/3, 2015 at 8:39 Comment(1)
Great tweak to this plugin! Do keep in mind that you also need to ensure this is rechecked upon window resizing, or otherwise the widths set are not in proportion to the document/body width for fluid/responsive designs.Cushman
P
2

can be well

.irs-line {
// needs latest Compass, add '@import "compass"' to your scss
@include background-image(linear-gradient(left,  #32ff6c 0%,#28ff57 33%,#207cca 33%,#2989d8 66%,#ff3030 66%,#ff0000 100%));
}
Punitive answered 12/3, 2015 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.