motion-v
Version:
<h1 align="center"> <img width="35" height="35" alt="Motion logo" src="https://github.com/user-attachments/assets/00d6d1c3-72c4-4c2f-a664-69da13182ffc" /><br />Motion for Vue</h1>
16 lines (15 loc) • 481 B
JavaScript
import { useMotionValueEvent } from "./use-motion-value-event.mjs";
import { frame, motionValue } from "motion-dom";
function useVelocity(value) {
const velocity = motionValue(value.getVelocity());
const updateVelocity = () => {
const latest = value.getVelocity();
velocity.set(latest);
if (latest) frame.update(updateVelocity);
};
useMotionValueEvent(value, "change", () => {
frame.update(updateVelocity, false, true);
});
return velocity;
}
export { useVelocity };