mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
Touch and tap gestures working
This commit is contained in:
@ -11,11 +11,13 @@
|
|||||||
// Simple touch gesture that triggers an event when an element is touched
|
// Simple touch gesture that triggers an event when an element is touched
|
||||||
framework.Gesture.Touch = {
|
framework.Gesture.Touch = {
|
||||||
handle: function(e) {
|
handle: function(e) {
|
||||||
|
if(e.type == 'touchstart') {
|
||||||
framework.EventController.trigger('touch', {
|
framework.EventController.trigger('touch', {
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
bubbles: true
|
bubbles: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simple tap gesture
|
// Simple tap gesture
|
||||||
@ -23,20 +25,21 @@
|
|||||||
handle: function(e) {
|
handle: function(e) {
|
||||||
switch(e.type) {
|
switch(e.type) {
|
||||||
case 'touchstart':
|
case 'touchstart':
|
||||||
|
this._touchStartX = e.touches[0].clientX;
|
||||||
|
this._touchStartY = e.touches[0].clientY;
|
||||||
|
|
||||||
// We are now touching
|
// We are now touching
|
||||||
this._isTouching = true;
|
this._isTouching = true;
|
||||||
// Reset the movement indicator
|
// Reset the movement indicator
|
||||||
this._hasMoved = false;
|
this._hasMoved = false;
|
||||||
break;
|
break;
|
||||||
case 'touchmove':
|
case 'touchmove':
|
||||||
this._touchStartX = e.type === 'touchstart' ? e.touches[0].clientX : e.clientX;
|
var x = e.touches[0].clientX;
|
||||||
this._touchStartY = e.type === 'touchstart' ? e.touches[0].clientY : e.clientY;
|
y = e.touches[0].clientY;
|
||||||
|
|
||||||
var x = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX,
|
|
||||||
y = e.type === 'touchmove' ? e.touches[0].clientY : e.clientY;
|
|
||||||
|
|
||||||
// Check if the finger moved more than 10px, and then indicate we should cancel the tap
|
// Check if the finger moved more than 10px, and then indicate we should cancel the tap
|
||||||
if (Math.abs(x - this._touchStartX) > 10 || Math.abs(y - this._touchStartY) > 10) {
|
if (Math.abs(x - this._touchStartX) > 10 || Math.abs(y - this._touchStartY) > 10) {
|
||||||
|
console.log('HAS MOVED');
|
||||||
this._hasMoved = true;
|
this._hasMoved = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user