* Checks if the tab is going to scroll and returns the scroll value
()
| 470 | * Checks if the tab is going to scroll and returns the scroll value |
| 471 | */ |
| 472 | function getScroll() { |
| 473 | const tabRight = tabLeft + tabWidth; |
| 474 | const scrollX = $parent.scrollLeft; |
| 475 | |
| 476 | /**@type {number} scroll value */ |
| 477 | let scroll = 0; |
| 478 | |
| 479 | // tab right should be greater than parent right |
| 480 | const rightDiff = tabRight - parentRight; |
| 481 | // tab left should be less than parent left |
| 482 | const leftDiff = parentLeft - tabLeft; |
| 483 | |
| 484 | const scrollSpeed = (diff) => { |
| 485 | const t = Math.min(diff / tabWidth, 1); |
| 486 | const eased = t * t; |
| 487 | return MIN_SCROLL_SPEED + eased * (MAX_SCROLL_SPEED - MIN_SCROLL_SPEED); |
| 488 | }; |
| 489 | |
| 490 | if (leftDiff > 0 && scrollX > MIN_SCROLL) { |
| 491 | scroll = -scrollSpeed(leftDiff); |
| 492 | } else if (rightDiff > 0 && scrollX < MAX_SCROLL) { |
| 493 | scroll = scrollSpeed(rightDiff); |
| 494 | } |
| 495 | |
| 496 | return scroll; |
| 497 | } |
no test coverage detected