2015-12-17 38 views
1

這是我從觸摸事件中獲得的返回數據。顯着缺失的是任何有用的觸摸X/Y座標(https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/changedTouches)。這是一個毫無希望的通用問題,但是,還有什麼想法? 「事件」對象傳遞給觸摸執行的功能:Touch in Angular

{ 
     "originalEvent": { 
     "isTrusted": true 
     }, 
     "type": "touchstart", 
     "timeStamp": 1450388006795, 
     "jQuery203026962137850932777": true, 
     "which": 0, 
     "view": "$WINDOW", 
     "target": {}, 
     "shiftKey": false, 
     "metaKey": false, 
     "eventPhase": 3, 
     "currentTarget": {}, 
     "ctrlKey": false, 
     "cancelable": true, 
     "bubbles": true, 
     "altKey": false, 
     "delegateTarget": {}, 
     "handleObj": { 
     "type": "touchstart", 
     "origType": "touchstart", 
     "data": null, 
     "guid": 2026, 
     "namespace": "" 
     }, 
     "data": null 
    } 

現在,這是在畫布的角度UI模式,但鼠標事件做工精細。這裏是我的元素BTW:

link: function(scope, element, attrs, model){ 
       //scope.canvasElem = element[0].children[0].children[0]; 
       scope.canvasElem = angular.element($('.touchScreen'))[0]; 
       scope.ctx = scope.canvasElem.getContext('2d'); 

下面是我如何綁定一個例子:

element.bind('touchstart', scope.touchStart); 

編輯,這裏是比較mouseDown事件對象:

{ 
    "originalEvent": { 
    "isTrusted": true 
    }, 
    "type": "mousedown", 
    "timeStamp": 1450389131400, 
    "jQuery20309114612976554781": true, 
    "toElement": {}, 
    "screenY": 436, 
    "screenX": 726, 
    "pageY": 375, 
    "pageX": 726, 
    "offsetY": 81, 
    "offsetX": 41, 
    "clientY": 375, 
    "clientX": 726, 
    "buttons": 1, 
    "button": 0, 
    "which": 1, 
    "view": "$WINDOW", 
    "target": {}, 
    "shiftKey": false, 
    "relatedTarget": null, 
    "metaKey": false, 
    "eventPhase": 3, 
    "currentTarget": {}, 
    "ctrlKey": false, 
    "cancelable": true, 
    "bubbles": true, 
    "altKey": false, 
    "delegateTarget": {}, 
    "handleObj": { 
    "type": "mousedown", 
    "origType": "mousedown", 
    "data": null, 
    "guid": 2025, 
    "namespace": "" 
    }, 
    "data": null 
} 

回答

1

它看起來就像你使用jQuery一樣,或者至少是一個類似於jQuery的實現。 jQuery不會將所有觸摸事件屬性複製到規範化事件包裝器。不過,您可以在originalEvent對象下找到它們。

originalEvent屬性包含本機觸摸事件,您可以根據規範使用該事件。

例如,像這樣的代碼:

$('body').on('touchmove', function(e) { 
    // Access the original event like this: 
    console.log(e.originalEvent); 
}); 
+0

嘿,我很欣賞的答覆,你可以在我如何獲得該包裝,請詳細點嗎? – VSO

+0

@VSO我添加了一個如何將原始事件對象記錄到控制檯的示例。 –

+0

我試過了,它返回的結果是:{「isTrusted」:true}。原始對象中的屬性(在我的問題文章中)就是我可以訪問的所有內容。我真的很希望我失去了一些東西。 – VSO