Jump to content

[SOLVED] How to prevent zoom on mobile devices?


ozRocker
 Share

Recommended Posts

When I drag my finger out of the viewport then back in, its registered as a 2nd touch and zooming kicks in.

I'm trying to register for "leaving" events but none of them are firing.  I have this

$("#canvas").on("mouseout touchleave dragleave touchcancel", function(e) {
    alert("touch out!");
});

This problem exists with Android and iOS.  This works on desktop browsers though.

Does anyone know which event I need to use?

Link to comment
Share on other sites

First, I would capture only the first touch event from the canvas into an array such as:

    function getTouchPos(e) {
        if (!e)
            var e = event;

        if(e.touches) {
            if (e.touches.length == 1) {
                var touch = e.touches[0];
                touchX=touch.pageX-touch.target.offsetLeft;
                touchY=touch.pageY-touch.target.offsetTop;
            }
        }
    }

And then use:

Event.preventDefault();

That should do it...

DB

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...