我目前正在使用Web应用程序,并想为其添加缩放功能。但是,HammerJS捏缩秤的方向错误。
我已经尝试过计算秤之间的差异,以确定它们是否要进出,但是感觉不够平稳,有点滞后。
//This is what I am using right now, it works but it is not going the direction I want, however it feels very smooth.
var scale = (e.scale * lastZoom);
//I have tried something like this, trying to use the velocity and adding it to the scale, this works for both in and out but it feels very laggy
var scale += Math.abs(velocity);
以下是捏事件返回的变量的完整列表,其中哪些变量有价值?
{pointers: Array(2), changedPointers: Array(1), pointerType: "touch", srcEvent: PointerEvent, isFirst: false, …}
additionalEvent: "pinchout"
angle: 0
center: {x: 178, y: 252}
changedPointers: [PointerEvent]
deltaTime: 115
deltaX: -2
deltaY: 0
direction: 1
distance: 0
eventType: 1
isFinal: false
isFirst: false
maxPointers: 2
offsetDirection: 2
overallVelocity: -0.017391304347826087
overallVelocityX: -0.017391304347826087
overallVelocityY: 0
pointerType: "touch"
pointers: []
preventDefault: ƒ ()
rotation: -358.5997411736357
scale: 1.001221903381003
srcEvent: PointerEvent {isTrusted: true, pointerId: 3, width: 1.0986328125, height: 1.0986328125, pressure: 1, …}
target: canvas#map
timeStamp: 1549011830464
type: "pinch"
velocity: 0
velocityX: 0
velocityY: 0
所以基本上,我想反转捏事件以在捏住时放大,而在捏住时缩小。