use animation time isntead of id

This commit is contained in:
Gerard Burns 2024-04-01 12:47:09 +01:00
parent 7eed50707e
commit 6fa66aae54
2 changed files with 10 additions and 8 deletions

View File

@ -129,7 +129,7 @@
} else {
console.log("not long enough");
}
}, 400)
}, 200)
}
const handleMouseleave = (e, option) => {

View File

@ -9,7 +9,7 @@
let targetX = 0
let targetY = 0
let animationId = 0;
let animationStartTime = 0;
let x = 0;
let y = 0;
@ -31,7 +31,7 @@
targetX = rect.x - tooltipWidth
targetY = rect.y
animationId += 1
animationStartTime = document.timeline.currentTime
if (x === 0 && y === 0) {
x = targetX
@ -39,14 +39,16 @@
}
}
const animate = (invokedAnimationId, xRate = null, yRate = null) => {
if (invokedAnimationId !== animationId) {
console.log("CANCEL ANIMATION ", invokedAnimationId, " ", animationId);
const animate = (invokedAnimationStartTime, frameTime, xRate = null, yRate = null) => {
console.log(frameTime);
if (invokedAnimationStartTime !== animationStartTime) {
console.log("CANCEL ANIMATION ", invokedAnimationStartTime, " ", animationStartTime);
return;
}
console.log("animating");
const animationDurationInFrames = 10;
const easingRate = 2;
const xDelta = targetX - x
const yDelta = targetY - y
@ -84,12 +86,12 @@
y = y - yRate;
}
requestAnimationFrame(() => animate(invokedAnimationId, xRate, yRate))
requestAnimationFrame((newFrameTime) => animate(invokedAnimationStartTime, newFrameTime, xRate, yRate))
}
$: updatePosition(anchor, tooltip)
$: updatePositionOnVisibilityChange(visible, hovering)
$: requestAnimationFrame(() => animate(animationId))
$: requestAnimationFrame((frameTime) => animate(animationStartTime, frameTime, null, null))
const handleMouseenter = (e) => {
hovering = true;