Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Adds a new option which sets the center of the fill bar at zero. Use… #342

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
horizontalClass: 'rangeslider--horizontal',
verticalClass: 'rangeslider--vertical',
fillClass: 'rangeslider__fill',
fillBeginsAtZero: false,
handleClass: 'rangeslider__handle',
startEvent: ['mousedown', 'touchstart', 'pointerdown'],
moveEvent: ['mousemove', 'touchmove', 'pointermove'],
Expand Down Expand Up @@ -383,8 +384,31 @@
value = this.getValueFromPosition(this.cap(pos, 0, this.maxHandlePos));
newPos = this.getPositionFromValue(value);

// Fill style
var fillDimension, fillDirection;
if (this.options.fillBeginsAtZero === true && 0 >= this.min && 0 <= this.max) {
var zeroPos = this.getPositionFromValue(0) + this.grabPos;
if (this.orientation === 'horizontal' && value >= 0) {
fillDirection = zeroPos;
fillDimension = newPos - zeroPos + this.grabPos;
} else if (this.orientation === 'horizontal' && value < 0) {
fillDirection = newPos + this.grabPos;
fillDimension = zeroPos - newPos - this.grabPos;
} else if (this.orientation === 'vertical' && value >= 0) {
fillDirection = zeroPos;
fillDimension = newPos - zeroPos + this.grabPos;
} else {
fillDirection = newPos + this.grabPos;
fillDimension = zeroPos - newPos - this.grabPos;
}
} else {
fillDimension = newPos + this.grabPos;
fillDirection = 0;
}

// Update ui
this.$fill[0].style[this.DIMENSION] = (newPos + this.grabPos) + 'px';
this.$fill[0].style[this.DIMENSION] = fillDimension + 'px';
this.$fill[0].style[this.DIRECTION_STYLE] = fillDirection + 'px';
this.$handle[0].style[this.DIRECTION_STYLE] = newPos + 'px';
this.setValue(value);

Expand Down