Trigger touch events with touch coords #270

Open
apoleshchuk opened this Issue Sep 8, 2011 · 3 comments

Projects

None yet

3 participants

@apoleshchuk

Sometimes need touchstart and touchend event coordinates in triggered event (tap, swipe, etc.).

Simple solutions – send touch object as data param when trigger target event:

$(touch.target).trigger('tap', {touch: touch});
yumyo commented Nov 8, 2011

Useful, thanks. Could you show a code sample to use the event coordinates as variables?

var layout = $(document.body),
    hotZoneSize = 0.25;

function getHotZone(x, y) {
        var o = layout.offset();

        if (x < o.left + o.width * hotZoneSize)
            return 'left';
        if (x > o.left + o.width * (1 - hotZoneSize))
            return 'right';

        return null;
    }
}
$(document.body).bind('tap swipeLeft swipeRight', function(event) {
    var touch = event.data.touch,
        // left or right hot zone on screen
        hotZone = getHotZone(touch.x2 || touch.x1 || 0);
});
@madrobby madrobby was assigned Apr 5, 2012
Owner
madrobby commented Sep 4, 2013

We'll possibly support this in the future, but you could just use two elements, overlay them and check for touch events separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment