abpetkov / powerange

iOS 7 style range slider
http://abpetkov.github.io/powerange/
423 stars 84 forks source link

Fix issue when min =! 0 and start = max showing wrong initial step #13

Closed cristiandouce closed 8 years ago

cristiandouce commented 9 years ago

When using a config like the following:


var range = new Powerange(el, {
  min: 1,
  max: 3,
  start: 3
})

The slider will init in the 2nd step instead of the last one.

This is caused because of the following steps iteration:

  // main.js:200
  for (i = 0; i <= dimension; i += interval) {
  // ...

The issue here is that when working with decimal numbers, in javascript 0.1 + 0.2 != 0.3 ever!

So, the <= evaluation never reaches the = part and therefore in those scenarios the this.steps array always ends up with less steps than it should have.

The solution I found is replacing the <= for a strict < and the top most dimension + 1 leading to this iteration:

  // main.js:200
  for (i = 0; i < dimension + 1; i += interval) {
  // ...

Working for both integer and decimal iterations!

And of course filling the this.steps array with the correct amount of steps.

Let me know what you think of this.