跳过主要内容

InertiaPlugin.getVelocity

InertiaPlugin.getVelocity( target:元素 | 字符串, property:字符串 ) ;

返回给定属性和目标对象的当前速度(只有当你已经开始使用InertiaPlugin.track()方法跟踪该属性后才有效)。

参数

  • 目标对象: 元素 | 字符串

    目标元素(可以是选择器文本)

  • 属性:字符串

    属性的名称,如 "x"、"rotation"、"left" 等

细节

返回给定属性和目标对象的当前速度(只有当你已经开始使用InertiaPlugin.track()方法跟踪该属性后才有效)。

示例

// track the x and y properties:
InertiaPlugin.track("#box", "x,y");

// then later, get the velocity:
let velocityX = InertiaPlugin.getVelocity("#box", "x");

为了获得最佳性能,您可以直接保留 .track() 调用返回的 VelocityTracker 对象,并通过该对象直接获取速度:

// track the x and y properties, but this time keep a reference to the VelocityTracker instance:
const tracker = InertiaPlugin.track("#box", "x,y")[0];

// then later, get the velocity:
let velocityX = tracker.get("x"),
velocityY = tracker.get("y");
无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗