1

I am using Ion.RangeSlider for a timeline. I have the setting hide_from_to: true as I don't want those labels to be seen.

However, there is one exception, where I would like that they are actually visible: when the user moves the handles.

That is, usually the slider should look like this:

Handle without label

But when moving the handle (and only then) it should look like this:

enter image description here

I tried with onChange, but I did not manage

$range.ionRangeSlider({
    type: "double",
    min: 4,
    ...,
    onChange: function (){
        hide_from_to = false,
    },
    ...

Here a jsfiddle.

Any ideas on how to do that?

J0ANMM
  • 7,849
  • 10
  • 56
  • 90
  • 1
    [Here](https://github.com/IonDen/ion.rangeSlider/issues/451) the comment of the owner in github: _this is not possible from the box. But you may write your own script on top of slider._ – J0ANMM Feb 24 '17 at 12:00

1 Answers1

2

This could be done very simple:

http://jsfiddle.net/IonDen/z8j5anno/

var $range = $(".js-range-slider");
var label;


function Label (container) {
    this.$label = $(container).find(".irs-single");
    this.active = false;
    this.ACTIVE = "irs-single--active";
}

Label.prototype = {   
    start: function () {
        if (!this.active) {
            this.active = true;
            this.$label.addClass(this.ACTIVE);
        }
    },

    end: function () {
        this.$label.removeClass(this.ACTIVE);
        this.active = false;
    }
};


$range.ionRangeSlider({
    type: "single",
    min: 0,
    max: 1000,
    from: 500,
    grid: true,
    onStart: function (data) {
        label = new Label(data.slider);
    },
    onChange: function () {
        label.start();
    },
    onFinish: function () {
        label.end();
    }
});
IonDen
  • 773
  • 5
  • 15
  • jsfiddle looks great. I did not manage to replicate it for my code, though: class `irs-single--active` is not added when moving the handle. Is any additional external resource needed to make it work? – J0ANMM Mar 27 '17 at 12:29
  • @J0ANMM, it was added in the end of CSS file, check it in the fiddle please. – IonDen Mar 27 '17 at 13:44
  • Yes. I had already updated the CSS. The problem is not with the CSS itself, but with the JS (I assume). When I do inspect element in my browser and move the handle, no class is added in the html code to the class `irs-single`. When I check your fiddle, the class `irs-single--active` is added when moving handles. It seems like something in `Label` is failing for me. – J0ANMM Mar 27 '17 at 14:26
  • 1
    @J0ANMM, also, please check that you are using latest version of a plugin. 2.1.7 or higher. Version 2.1.6 contains a bug, which will prevent this feature from working. – IonDen Mar 27 '17 at 14:36
  • I had indeed version 2.1.6! Thanks! – J0ANMM Mar 27 '17 at 15:14
  • @IonDen Thanks for the code. But what I need to change to make it work for dual knob? – Rohit Gupta Jul 26 '17 at 05:12