Search code examples
javascriptandroidhtmldom-eventspinchzoom

Zooming or wheeling on a mobile browser


In a desktop browser, I detect the mouse wheel use with the standard mousewheel or DOMMouseScroll events. I can thus change a canvas (zooming in a kind of map).

Now I want to bring this feature to my mobile users : I need to intercept the standard pinch-zoom gestures (without zooming the page). Is that possible today ? Is it possible to get the center of the gesture (for localized zoom and unzoom) ?

Note that it needs to work on the standard browser of Android 4.2. Other browsers/devices aren't in the scope of this question, which may make it easier.


Solution

  • This seems fixed on 3.0. This is a test page that seems to work on my ICS tablet. This is an excerpt from the linked test page:

    // Touch events seem to work in iOS, Android browser 3.0 and up,
    // and various 3rd-party Android browsers, now including FireFox
    // (Nightly as of 03-Feb-2012, not enabled by default yet).
    eventTarget.addEventListener('touchstart', HandleTouchStart, false);
    document.addEventListener('touchmove', HandleTouchMove, false);
    document.addEventListener('touchend', HandleTouchEnd, false);
    document.addEventListener('touchcancel', HandleTouchCancel, false);