X / Y Touch Coordinates for iOS / Mobile

I am creating a web application that I want to use on mobile devices. The initial mechanic of this application requires the current X / Y coordinates of the mouse, which does not require clicking and dragging, just moving the mouse around the browser window.

Now I am looking through various jQuery / Javascript libraries regarding Touch and Gestures, but I can not find anything that matches what I need.

So basically, I am looking for a way to get x / y pos with one finger touch / drag.

For example: tap the screen at 0.0, then hold and drag it to 480.320. Then the values ​​will interpolate between x1, y1-x2, y2.

Thank.

+3
source share
2 answers

, , touchstart, touchmove touchhend.

http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/

, iOS , , , , iOS , .

+4
$(function() {
    var $log = $("#log");

    function updateLog(x, y) {
        $log.html('X: '+x+'; Y: '+y);
    }

    document.addEventListener('touchstart', function(e) {
        updateLog(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
    }, false);

    document.addEventListener('touchmove', function(e) {
        e.preventDefault();
        updateLog(e.targetTouches[0].pageX, e.targetTouches[0].pageY);
    }, false);
});
+10

All Articles