refactor some
This commit is contained in:
parent
108f9667f6
commit
8631b3ae75
|
@ -3,7 +3,6 @@
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
export let currentTooltip
|
export let currentTooltip
|
||||||
export let previousTooltip
|
|
||||||
export let anchor
|
export let anchor
|
||||||
export let visible = false
|
export let visible = false
|
||||||
export let hovering = false
|
export let hovering = false
|
||||||
|
@ -16,21 +15,15 @@
|
||||||
let currentTooltipWidth = 0
|
let currentTooltipWidth = 0
|
||||||
let currentTooltipHeight = 0
|
let currentTooltipHeight = 0
|
||||||
|
|
||||||
let previousTooltipWidth = 0
|
|
||||||
let previousTooltipHeight = 0
|
|
||||||
|
|
||||||
const updatePositionOnVisibilityChange = (visible, hovering) => {
|
const updatePositionOnVisibilityChange = (visible, hovering) => {
|
||||||
if (!visible && !hovering) {
|
if (!visible && !hovering) {
|
||||||
previousX = 0;
|
previousX = 0;
|
||||||
previousY = 0;
|
previousY = 0;
|
||||||
|
|
||||||
previousTooltipWidth = 0
|
|
||||||
previousTooltipHeight = 0
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
const updatePosition = (anchor, currentTooltip, previousTooltip) => {
|
const updatePosition = (anchor, currentTooltip) => {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
if (anchor == null || currentTooltip == null || previousTooltip == null) {
|
if (anchor == null || currentTooltip == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,17 +32,6 @@
|
||||||
currentTooltipWidth = currentTooltip.clientWidth
|
currentTooltipWidth = currentTooltip.clientWidth
|
||||||
currentTooltipHeight = currentTooltip.clientHeight
|
currentTooltipHeight = currentTooltip.clientHeight
|
||||||
|
|
||||||
previousTooltipWidth = previousTooltip.clientWidth
|
|
||||||
previousTooltipHeight = previousTooltip.clientHeight
|
|
||||||
|
|
||||||
if (previousTooltipWidth === 0) {
|
|
||||||
previousTooltipWidth = currentTooltipWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (previousTooltipHeight === 0) {
|
|
||||||
previousTooltipHeight = currentTooltipHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
previousX = currentX
|
previousX = currentX
|
||||||
previousY = currentY
|
previousY = currentY
|
||||||
|
|
||||||
|
@ -125,7 +107,7 @@
|
||||||
requestAnimationFrame((newFrameTime) => animate(invokedAnimationStartTime, newFrameTime))
|
requestAnimationFrame((newFrameTime) => animate(invokedAnimationStartTime, newFrameTime))
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
$: updatePosition(anchor, currentTooltip, previousTooltip)
|
$: updatePosition(anchor, currentTooltip)
|
||||||
$: updatePositionOnVisibilityChange(visible, hovering)
|
$: updatePositionOnVisibilityChange(visible, hovering)
|
||||||
/*$: requestAnimationFrame((frameTime) => animate(animationStartTime, frameTime))*/
|
/*$: requestAnimationFrame((frameTime) => animate(animationStartTime, frameTime))*/
|
||||||
|
|
||||||
|
@ -162,7 +144,6 @@
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
bind:this={previousTooltip}
|
|
||||||
class="previousContent"
|
class="previousContent"
|
||||||
style:left={`${previousX}px`}
|
style:left={`${previousX}px`}
|
||||||
style:top={`${previousY}px`}
|
style:top={`${previousY}px`}
|
||||||
|
|
Loading…
Reference in New Issue