useVelocity
useVelocity
接受一个motion 值并返回一个新的 motion 值,该值会根据提供的 motion 值的速度进行更新。
<script setup> const x = useMotionValue(0) const xVelocity = useVelocity(x) const scale = useTransform( xVelocity, [-3000, 0, 3000], [2, 1, 2], { clamp: false } ) </script> <template> <Motion drag="x" :style="{ x, scale }" /> </template>
用法
从 Motion 导入 useVelocity
import { useVelocity } from "motion-v"
将任何数值类型的 motion 值传递给 useVelocity
。它将返回一个新的 motion 值,该值会根据原始值的速度进行更新。
<script setup> import { useMotionValue, useVelocity, useMotionValueEvent } from 'motion-v' const x = useMotionValue(0) const xVelocity = useVelocity(x) useMotionValueEvent(xVelocity, 'change', (latest) => { console.log('Velocity', latest) }) </script> <template> <Motion :style="{ x }" /> </template>
任何数值类型的 motion 值都适用。即使是从 useVelocity
返回的值也可以。
const x = useMotionValue(0) const xVelocity = useVelocity(x) const xAcceleration = useVelocity(xVelocity)
useVelocity
接受一个motion 值并返回一个新的 motion 值,该值会根据提供的 motion 值的速度进行更新。
<script setup> const x = useMotionValue(0) const xVelocity = useVelocity(x) const scale = useTransform( xVelocity, [-3000, 0, 3000], [2, 1, 2], { clamp: false } ) </script> <template> <Motion drag="x" :style="{ x, scale }" /> </template>
用法
从 Motion 导入 useVelocity
import { useVelocity } from "motion-v"
将任何数值类型的 motion 值传递给 useVelocity
。它将返回一个新的 motion 值,该值会根据原始值的速度进行更新。
<script setup> import { useMotionValue, useVelocity, useMotionValueEvent } from 'motion-v' const x = useMotionValue(0) const xVelocity = useVelocity(x) useMotionValueEvent(xVelocity, 'change', (latest) => { console.log('Velocity', latest) }) </script> <template> <Motion :style="{ x }" /> </template>
任何数值类型的 motion 值都适用。即使是从 useVelocity
返回的值也可以。
const x = useMotionValue(0) const xVelocity = useVelocity(x) const xAcceleration = useVelocity(xVelocity)
useVelocity
接受一个motion 值并返回一个新的 motion 值,该值会根据提供的 motion 值的速度进行更新。
<script setup> const x = useMotionValue(0) const xVelocity = useVelocity(x) const scale = useTransform( xVelocity, [-3000, 0, 3000], [2, 1, 2], { clamp: false } ) </script> <template> <Motion drag="x" :style="{ x, scale }" /> </template>
用法
从 Motion 导入 useVelocity
import { useVelocity } from "motion-v"
将任何数值类型的 motion 值传递给 useVelocity
。它将返回一个新的 motion 值,该值会根据原始值的速度进行更新。
<script setup> import { useMotionValue, useVelocity, useMotionValueEvent } from 'motion-v' const x = useMotionValue(0) const xVelocity = useVelocity(x) useMotionValueEvent(xVelocity, 'change', (latest) => { console.log('Velocity', latest) }) </script> <template> <Motion :style="{ x }" /> </template>
任何数值类型的 motion 值都适用。即使是从 useVelocity
返回的值也可以。
const x = useMotionValue(0) const xVelocity = useVelocity(x) const xAcceleration = useVelocity(xVelocity)