mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Finish sliding active tab indicator
This commit is contained in:
parent
9eac9ae935
commit
2040a356fd
@ -14,26 +14,18 @@
|
|||||||
const activeIndicatorRight = tweened(0, { easing: cubicInOut, duration: 400 });
|
const activeIndicatorRight = tweened(0, { easing: cubicInOut, duration: 400 });
|
||||||
const liElements = {};
|
const liElements = {};
|
||||||
let navEl;
|
let navEl;
|
||||||
let activeLiEl;
|
|
||||||
|
|
||||||
function select(tabKey, activeLi) {
|
function select(tabKey) {
|
||||||
selectedKey = tabKey;
|
selectedKey = tabKey;
|
||||||
activeLiEl = activeLi;
|
|
||||||
dispatch('select', tabKey);
|
dispatch('select', tabKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveActiveIndicator(target) {
|
function moveActiveIndicator(target = liElements[selectedKey]) {
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const navRect = navEl.getBoundingClientRect();
|
const navRect = navEl.getBoundingClientRect();
|
||||||
if (!target) {
|
|
||||||
const activeLiRect = activeLiEl?.getBoundingClientRect() || navRect;
|
|
||||||
$activeIndicatorLeft = activeLiRect.x - navRect.x;
|
|
||||||
$activeIndicatorRight = navRect.right - activeLiRect.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
const itemRect = target.getBoundingClientRect();
|
const itemRect = target.getBoundingClientRect();
|
||||||
$activeIndicatorLeft = itemRect.x - navRect.x;
|
$activeIndicatorLeft = itemRect.x - navRect.x;
|
||||||
$activeIndicatorRight = navRect.right - itemRect.right;
|
$activeIndicatorRight = navRect.right - itemRect.right;
|
||||||
@ -57,7 +49,7 @@
|
|||||||
on:mouseenter={event => moveActiveIndicator(event.target)}
|
on:mouseenter={event => moveActiveIndicator(event.target)}
|
||||||
on:mouseleave={() => moveActiveIndicator()}
|
on:mouseleave={() => moveActiveIndicator()}
|
||||||
>
|
>
|
||||||
<button class="tab" on:click={event => select(tab.key, event.target.parentElement)}>
|
<button class="tab" on:click={() => select(tab.key)}>
|
||||||
{#if tab.icon} <Icon name={tab.icon} /> {/if}
|
{#if tab.icon} <Icon name={tab.icon} /> {/if}
|
||||||
<span class="label">{tab.title}</span>
|
<span class="label">{tab.title}</span>
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user