UNPKG

@minix-iot/ui

Version:

基于Vue的移动端轻量级UI组件库

44 lines (33 loc) 816 B
export class Inertia { static LIMIT_TIME = 300; static LIMIT_DISTANCE = 15; static Create() { return new Inertia(); } constructor() { this.startTime = 0; this.startOffset = 0; this.endTime = 0; this.endOffset = 0; } get shouldActive() { return Math.abs(this.interval) < Inertia.LIMIT_TIME && Math.abs(this.distance) > Inertia.LIMIT_DISTANCE; } get interval() { return this.endTime - this.startTime; } get distance() { return this.endOffset - this.startOffset; } get speed() { return this.distance / this.interval; } start(startOffset, startTime = Date.now()) { this.startOffset = startOffset; this.startTime = startTime; } end(endOffset, endTime = Date.now()) { this.endOffset = endOffset; this.endTime = endTime; } }