Skip to content

Commit

Permalink
fix: moves per click count edge case #12
Browse files Browse the repository at this point in the history
  • Loading branch information
koleCar committed Feb 20, 2019
1 parent 332a222 commit bb108e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 29 additions & 8 deletions projects/ng-slider/src/lib/slides/slides.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,45 @@ export class SlidesComponent implements OnInit, AfterViewInit, OnDestroy {

move(right = true, amount = 1) {
this._resetTimer();
let nextPosition;

let move: boolean;

if (right) {
this.left -= this.slideWidthPercentage * amount;
nextPosition = this.left - this.slideWidthPercentage * amount;
move = true;
} else {
this.left += this.slideWidthPercentage * amount;
nextPosition = this.left + this.slideWidthPercentage * amount;
move = false;
}

const gap = this.slideWidthPercentage * (amount - 1);
const loop = this.options.loop;
if (this.left < this.maxLeft) {
loop ? (this.left = 0) : (this.left = this.maxLeft);
} else if (this.left > 0) {
amount = this.options.blocksPerView;
loop ? (this.left = this.maxLeft) : (this.left = 0);

switch (true) {
case nextPosition < this.maxLeft && nextPosition >= this.maxLeft - gap:
case nextPosition < this.maxLeft &&
!(nextPosition >= this.maxLeft - gap) &&
!loop:
this.left = this.maxLeft;
break;
case nextPosition < this.maxLeft &&
!(nextPosition >= this.maxLeft - gap) &&
loop:
case nextPosition > 0 && nextPosition <= gap:
this.left = 0;
break;
case nextPosition > 0 && !(nextPosition <= gap) && loop:
amount = this.options.blocksPerView;
this.left = this.maxLeft;
break;
case nextPosition > 0 && !(nextPosition <= gap) && !loop:
amount = this.options.blocksPerView;
this.left = 0;
break;
default:
this.left = nextPosition;
}

this._shouldEmitSlideInView(amount, move);

this.cdr.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/app/simple-example/simple-example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SimpleExampleComponent {
sliderOptions: Partial<SliderOptions> = {
blocksPerView: 3,
slideTime: 5000,
movesPerClick: 1,
movesPerClick: 2,
loop: true
};

Expand Down

0 comments on commit bb108e4

Please sign in to comment.