最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - nouislider with custom values instead of range - Stack Overflow

programmeradmin1浏览0评论

I like noUIslider slider but I need to apply custom values instead of range and step options, as my values are not changing fluently.

So instead having for example: range [10,90] step: 5

I would like to use:

values [0,10, 15.5, 18, 41, etc...]

Is it possible?

Thanks

I like noUIslider slider but I need to apply custom values instead of range and step options, as my values are not changing fluently.

So instead having for example: range [10,90] step: 5

I would like to use:

values [0,10, 15.5, 18, 41, etc...]

Is it possible?

Thanks

Share Improve this question asked Feb 28, 2014 at 8:59 nickornottonickornotto 2,1664 gold badges42 silver badges75 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

The Solution is the range option. You'll have to make an object with the values for the postion on the slider, the value at that postion and the distance to the next value.

var rangers = {}
for (i = 0; i < filterLength.length; ++i) {
  var prozent = Math.ceil((100/filterLength.length) * i)
  if ( i < filterLength.length-1 ) { rangers[prozent+'%'] = [ filterLength[i],  filterLength[i+1] - filterLength[i] ] }
  if ( i == filterLength.length-1 ) { rangers['max'] = [filterLength[filterLength.length-1]]; }
}

$("#slider-length").noUiSlider({
  start: [ filterLength[0], filterLength[filterLength.length-1] ],
  range: rangers
});

You can set custom non-linear values.

range: {
    'min': [ 0 ],
    '10%': [ 500, 500 ],
    '50%': [ 4000, 1000 ],
    'max': [ 10000 ]
},

See example here http://refreshless./nouislider/examples/non-linear

I used TypeScript to solve this problem You may not need the word this and Define your numeric array in a different way.

Range for two handle:

intRangeeeee: number[] = [];
  rangers = {};    
for (let i = 0; i < this.intRangeeeee.length; ++i) {
          var prozent = Math.ceil((100 / this.intRangeeeee.length) * i)
          if (prozent === 0) {
            this.rangers['min'] = [this.intRangeeeee[i], this.intRangeeeee[i + 1] - 
            this.intRangeeeee[i]];
          } else {
            if ( i < this.intRangeeeee.length-1 ) { this.rangers[prozent+'%'] = [ this.intRangeeeee[i],  this.intRangeeeee[i+1] - this.intRangeeeee[i] ] }
          }
          
          if ( i == this.intRangeeeee.length-1 ) { this.rangers['max'] = [this.intRangeeeee[this.intRangeeeee.length-1]]; }
        }

and for only one handle

for (let i = 0; i < this.intRangeeeee.length; ++i) {
      var prozent = Math.ceil((100 / this.intRangeeeee.length) * i)
      if (prozent === 0) {
        this.rangers['min'] = [this.intRangeeeee[i]];
      } else {
        if ( i < this.intRangeeeee.length-1 ) { this.rangers[prozent+'%'] = [this.intRangeeeee[i]] }
      }
      if ( i == this.intRangeeeee.length-1 ) { this.rangers['max'] = [this.intRangeeeee[this.intRangeeeee.length-1]]; }
    }

this.mySlider = {
      connect: [true,false],
      start: [ this.intRangeeeee[0]],
      behaviour: 'tap',
      snap: true,
      range: this.rangers
    }
发布评论

评论列表(0)

  1. 暂无评论