Simplest way to detect a pinch
You want to use the gesturestart
, gesturechange
, and gestureend
events. These get triggered any time 2 or more fingers touch the screen.
Depending on what you need to do with the pinch gesture, your approach will need to be adjusted. The scale
multiplier can be examined to determine how dramatic the user's pinch gesture was. See Apple's TouchEvent documentation for details about how the scale
property will behave.
node.addEventListener('gestureend', function(e) {
if (e.scale < 1.0) {
// User moved fingers closer together
} else if (e.scale > 1.0) {
// User moved fingers further apart
}
}, false);
You could also intercept the gesturechange
event to detect a pinch as it happens if you need it to make your app feel more responsive.
Hammer.js: How to detect pinch with any number of / multiple fingers
Well I finally solved it! I don't know if it's a hack but it works!
The solution was quite simple in the end and it was to set the pointers option to 0, yes zero!
var multiPinch = new Hammer.Pinch({event: 'multipinch', pointers: 0, threshold: 0});
Now, this "multipinch" event detects pinches with any number of pointers ranging from 2 to 10.
This was inspired from the docs here: http://hammerjs.github.io/recognizer-pinch/
which say for the pointers option:
| Option | Default | Description |
|:--------:|---------|-----------------------------------------|
| pointers | 1 | Required pointers. 0 for all pointers. |
So, I tried setting pointers option to 0 for the pinch event and lo, it worked!
How to detect pinch in gesture vs pinch out gesture?
Well, that seems an easy one. The UIPinchGestureRecognizer
class has only two properties, scale
and velocity
. It seems logical that a negative scale
would mean an inward pinch, a positive scale
an outward pinch.
NB: "negative" might be misleading. "Smaller" is 0.0 < scale < 1.0
, "bigger" is scale > 1.0
.
jQuery mobile: Pinch/Zoom/Scale Gesture - console.log('something');
The vendor support varies and iOS the only platform whereto use multi-touch Javascript events reliably.
http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW8
From Apple's own documentation.
Is it possible to detect pinch zoom start and end gestures in Eclair (2.1)?
I don't believe so. It would appear that SimpleGestureDectector is only available in API level 8+.
Related Topics
Combination of Animation and Transition Not Working Properly
Why Is Element Not Being Shown Before Alert
Padding or Margin Value in Pixels as Integer Using Jquery
Polymer Share Styles Across Elements
Screen Styling When Virtual Keyboard Is Active
Jquery Event That Triggers After CSS Is Loaded
How to Animate a Progressive Drawing of Svg Path
Count Down Timer with Circular Progress Bar
How to Make Changeable Themes Using CSS and JavaScript
What Is the Best Method to Reduce the Size of My JavaScript and CSS Files
Generate Dynamic CSS Based on Variables Angular
Vertical Centering Variable Height Image While Maintaining Max-Width/Height
Toggle Visibility Property of Div
How to Determine If JavaScript Array Contains an Object With an Attribute That Equals a Given Value
State Not Updating When Using React State Hook Within Setinterval