UNPKG

motion-v

Version:

<p align="center"> <img width="100" height="100" alt="Motion logo" src="https://user-images.githubusercontent.com/7850794/164965523-3eced4c4-6020-467e-acde-f11b7900ad62.png" /> </p> <h1 align="center">Motion for Vue</h1>

21 lines (20 loc) 684 B
import { useMotionValueEvent } from "./use-motion-value-event.mjs"; import { motionValue } from "../external/.pnpm/motion-dom@12.16.0/external/motion-dom/dist/es/value/index.mjs"; import { frame } from "../external/.pnpm/motion-dom@12.16.0/external/motion-dom/dist/es/frameloop/frame.mjs"; 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 };