I need to track user touch events. I want to track when user swipes from edges.
For example when user swipes from left vertical edge I will show a menu, from right edge
I think this will work:
first check if the touchstart event happens at the edge of the screen:
var startDragAtBorder = false;
$(document).on('touchstart', function(e) {
var xPos = e.originalEvent.touches[0].pageX;
if(xPos < 5) { // this can also be xPos == 0; whatever works for you
startDragAtBorder = true;
}
else{
startDragAtBorder = false;
}
});
than setup the drag event with Hammer:
$(document).hammer().on('drag', function(e){
if(startDragAtBorder && e.gesture.direction == 'right'){
// check that the drag event started at the edge and that the direction is to the right
var currentText = $('#logArea').text();
$('#logArea').text(""+currentText+" . "+e.type);
}
});
working fiddle: http://jsfiddle.net/ym4JV/55/