* Scrolls to given position. Respects scroll bounds. * @param {Number} [x=0] Scroll position. * @return {PipeView} Fluent interface
(x = 0)
| 510 | * @return {PipeView} Fluent interface |
| 511 | */ |
| 512 | scrollTo (x = 0) { |
| 513 | // Remove decimal digits |
| 514 | x = parseInt(x) |
| 515 | |
| 516 | // Respect bounds |
| 517 | x = Math.max(Math.min(x, this._scrollMax), 0) |
| 518 | |
| 519 | // Only proceed when something has changed |
| 520 | if (this._scrollPosition !== x) { |
| 521 | // Left scroll handle |
| 522 | if (x === 0) { |
| 523 | this._$scrollHandleLeft.classList.add(scrollHandleDisabledClass) |
| 524 | this.scrollHandleDidStop() |
| 525 | } else if (this._scrollPosition === 0) { |
| 526 | this._$scrollHandleLeft.classList.remove(scrollHandleDisabledClass) |
| 527 | } |
| 528 | |
| 529 | // Right scroll handle |
| 530 | if (x === this._scrollMax) { |
| 531 | this._$scrollHandleRight.classList.add(scrollHandleDisabledClass) |
| 532 | this.scrollHandleDidStop() |
| 533 | } else if (this._scrollPosition === this._scrollMax) { |
| 534 | this._$scrollHandleRight.classList.remove(scrollHandleDisabledClass) |
| 535 | } |
| 536 | |
| 537 | // Apply change to DOM |
| 538 | this._$content.style.transform = x > 0 ? `translate(${-x}px, 0)` : '' |
| 539 | |
| 540 | this._scrollPosition = x |
| 541 | } |
| 542 | return this |
| 543 | } |
| 544 | } |
no test coverage detected