css impl working i think
This commit is contained in:
parent
fb25c08523
commit
108f9667f6
|
@ -8,10 +8,10 @@
|
||||||
export let visible = false
|
export let visible = false
|
||||||
export let hovering = false
|
export let hovering = false
|
||||||
|
|
||||||
let startX = 0
|
let previousX = 0
|
||||||
let startY = 0
|
let previousY = 0
|
||||||
let endX = 0
|
let currentX = 0
|
||||||
let endY = 0
|
let currentY = 0
|
||||||
|
|
||||||
let currentTooltipWidth = 0
|
let currentTooltipWidth = 0
|
||||||
let currentTooltipHeight = 0
|
let currentTooltipHeight = 0
|
||||||
|
@ -19,17 +19,10 @@
|
||||||
let previousTooltipWidth = 0
|
let previousTooltipWidth = 0
|
||||||
let previousTooltipHeight = 0
|
let previousTooltipHeight = 0
|
||||||
|
|
||||||
let x = 0;
|
|
||||||
let y = 0;
|
|
||||||
let w = 0;
|
|
||||||
let h = 0;
|
|
||||||
|
|
||||||
let animationStartTime = 0;
|
|
||||||
|
|
||||||
const updatePositionOnVisibilityChange = (visible, hovering) => {
|
const updatePositionOnVisibilityChange = (visible, hovering) => {
|
||||||
if (!visible && !hovering) {
|
if (!visible && !hovering) {
|
||||||
x = 0;
|
previousX = 0;
|
||||||
y = 0;
|
previousY = 0;
|
||||||
|
|
||||||
previousTooltipWidth = 0
|
previousTooltipWidth = 0
|
||||||
previousTooltipHeight = 0
|
previousTooltipHeight = 0
|
||||||
|
@ -57,21 +50,24 @@
|
||||||
previousTooltipHeight = currentTooltipHeight;
|
previousTooltipHeight = currentTooltipHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
startX = x
|
previousX = currentX
|
||||||
startY = y
|
previousY = currentY
|
||||||
|
|
||||||
endX = rect.x - currentTooltipWidth
|
// - width to align to left side of anchor
|
||||||
endY = rect.y
|
currentX = rect.x - currentTooltipWidth
|
||||||
|
currentY = rect.y
|
||||||
|
|
||||||
animationStartTime = document.timeline.currentTime
|
if (previousX === 0) {
|
||||||
|
previousX = currentX
|
||||||
|
}
|
||||||
|
|
||||||
if (x === 0 && y === 0) {
|
if (previousY === 0) {
|
||||||
startX = endX
|
previousY = currentY
|
||||||
startY = endY
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
const getNormalizedTime = (startTime, endTime, currentTime) => {
|
const getNormalizedTime = (startTime, endTime, currentTime) => {
|
||||||
const distanceFromStart = currentTime - startTime;
|
const distanceFromStart = currentTime - startTime;
|
||||||
const timeDiff = endTime - startTime;
|
const timeDiff = endTime - startTime;
|
||||||
|
@ -125,17 +121,13 @@
|
||||||
x = linearInterpolation(startX, endX, easing.x)
|
x = linearInterpolation(startX, endX, easing.x)
|
||||||
y = linearInterpolation(startY, endY, easing.y)
|
y = linearInterpolation(startY, endY, easing.y)
|
||||||
w = linearInterpolation(previousTooltipWidth, currentTooltipWidth, easing.x)
|
w = linearInterpolation(previousTooltipWidth, currentTooltipWidth, easing.x)
|
||||||
console.log(currentTooltipWidth);
|
|
||||||
console.log(previousTooltipWidth);
|
|
||||||
console.log(w);
|
|
||||||
console.log("")
|
|
||||||
|
|
||||||
requestAnimationFrame((newFrameTime) => animate(invokedAnimationStartTime, newFrameTime))
|
requestAnimationFrame((newFrameTime) => animate(invokedAnimationStartTime, newFrameTime))
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$: updatePosition(anchor, currentTooltip, previousTooltip)
|
$: updatePosition(anchor, currentTooltip, previousTooltip)
|
||||||
$: updatePositionOnVisibilityChange(visible, hovering)
|
$: updatePositionOnVisibilityChange(visible, hovering)
|
||||||
$: requestAnimationFrame((frameTime) => animate(animationStartTime, frameTime))
|
/*$: requestAnimationFrame((frameTime) => animate(animationStartTime, frameTime))*/
|
||||||
|
|
||||||
const handleMouseenter = (e) => {
|
const handleMouseenter = (e) => {
|
||||||
hovering = true;
|
hovering = true;
|
||||||
|
@ -150,29 +142,30 @@
|
||||||
<div
|
<div
|
||||||
on:mouseenter={handleMouseenter}
|
on:mouseenter={handleMouseenter}
|
||||||
on:mouseleave={handleMouseleave}
|
on:mouseleave={handleMouseleave}
|
||||||
style:width={`${w}px`}
|
style:width={`${currentTooltipWidth}px`}
|
||||||
style:height={`${currentTooltipHeight}px`}
|
style:height={`${currentTooltipHeight}px`}
|
||||||
style:left={`${x}px`}
|
style:left={`${currentX}px`}
|
||||||
style:top={`${y}px`}
|
style:top={`${currentY}px`}
|
||||||
class="tooltip"
|
class="tooltip"
|
||||||
class:visible={visible || hovering}
|
class:visible={visible || hovering}
|
||||||
>
|
>
|
||||||
<div class="screenSize">
|
<div class="screenSize"
|
||||||
|
style:left={`${-currentX}px`}
|
||||||
|
style:top={`${-currentY}px`}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
|
style:left={`${currentX}px`}
|
||||||
|
style:top={`${currentY}px`}
|
||||||
bind:this={currentTooltip}
|
bind:this={currentTooltip}
|
||||||
class="currentContent"
|
class="currentContent"
|
||||||
style:left={`${endX - x}px`}
|
|
||||||
style:top={`${endY - y}px`}
|
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="screenSize">
|
|
||||||
<div
|
<div
|
||||||
bind:this={previousTooltip}
|
bind:this={previousTooltip}
|
||||||
class="previousContent"
|
class="previousContent"
|
||||||
style:left={`${startX - x}px`}
|
style:left={`${previousX}px`}
|
||||||
style:top={`${startY - y}px`}
|
style:top={`${previousY}px`}
|
||||||
>
|
>
|
||||||
<slot name="previous"/>
|
<slot name="previous"/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -181,10 +174,13 @@
|
||||||
</Portal>
|
</Portal>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
/* Screen width absolute parent for tooltip content so that'd the applied width and height
|
||||||
|
to the root doesn't affect their size */
|
||||||
.screenSize {
|
.screenSize {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
transition: top 300ms ease-in, left 300ms ease-in;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tooltip {
|
.tooltip {
|
||||||
|
@ -194,6 +190,7 @@
|
||||||
background-color: red;
|
background-color: red;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
transition: width 300ms ease-in, height 300ms ease-in, top 300ms ease-in, left 300ms ease-in;
|
||||||
}
|
}
|
||||||
|
|
||||||
.visible {
|
.visible {
|
||||||
|
|
Loading…
Reference in New Issue