diff options
Diffstat (limited to 'src/scripts/lib/tabbar.ts')
| -rw-r--r-- | src/scripts/lib/tabbar.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/scripts/lib/tabbar.ts b/src/scripts/lib/tabbar.ts new file mode 100644 index 0000000..6a3d3d3 --- /dev/null +++ b/src/scripts/lib/tabbar.ts | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | export function mountTabbar() { | ||
| 2 | const tabbarEls = document.querySelectorAll<HTMLElement>(".o-tabbar__tabs"); | ||
| 3 | |||
| 4 | for (const tabbarEl of tabbarEls) { | ||
| 5 | const selectedItemEl = tabbarEl.querySelector<HTMLElement>(".o-tabbar__tab.is-selected"); | ||
| 6 | |||
| 7 | if (selectedItemEl) { | ||
| 8 | tabbarEl.scrollLeft = | ||
| 9 | selectedItemEl.offsetLeft - 0.5 * tabbarEl.clientWidth + 0.5 * selectedItemEl.clientWidth; | ||
| 10 | } | ||
| 11 | } | ||
| 12 | } | ||
