admin管理员组文章数量:1399964
Edit: "This can't be done in Angular UI Modals" is a valid answer, if that's actually the case.
This is the return data I get from a touch event. Conspicuously missing are any useful touch X/Y coords (). This is a hopelessly generic question, but nonetheless, any ideas? The "event" object passed to the function executed on touch:
{
"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
}
Now, this IS in an angular UI modal in canvas, but mouse events work fine. Here is my element 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');
Here is an example of how I bind:
element.bind('touchstart', scope.touchStart);
Edit, and here is a mousedown event object for parison:
{
"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
}
Edit: "This can't be done in Angular UI Modals" is a valid answer, if that's actually the case.
This is the return data I get from a touch event. Conspicuously missing are any useful touch X/Y coords (https://developer.mozilla/en-US/docs/Web/API/TouchEvent/changedTouches). This is a hopelessly generic question, but nonetheless, any ideas? The "event" object passed to the function executed on touch:
{
"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
}
Now, this IS in an angular UI modal in canvas, but mouse events work fine. Here is my element 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');
Here is an example of how I bind:
element.bind('touchstart', scope.touchStart);
Edit, and here is a mousedown event object for parison:
{
"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
}
Share
Improve this question
edited Dec 17, 2015 at 22:28
VSO
asked Nov 29, 2015 at 0:42
VSOVSO
12.7k28 gold badges116 silver badges201 bronze badges
3 Answers
Reset to default 2For example you can bind the touch events using directives, inside the directive could have a code like this,
element.on('touchstart', function (event) {
event = event.originalEvent || event;
//actions
event.stopPropagation(); //if you need stop the propagation of the event
});
also need to have careful about the behavior of the 4 types of touch events (touchstart, touchend, touchmove, touchcancel) depending on your goals. For capture the position of the cursor use,
element.on('touchmove', function (event) {
event.preventDefault();
if (event.targetTouches.length == 1) { //when only has one target in touch
var touch = event.targetTouches[0];
// Place element where the finger is
var x = touch.pageX + 'px';
var y = touch.pageY + 'px';
}
event.stopPropagation();
});
var touchRelativeToViewWindow = {
x: event.originalEvent.touches[0].pageX,
y: event.originalEvent.touches[0].pageY
};
Better late than never (note, this is for touchmove
):
When going through AngularJs/jQuery, we need to look in the originalEvent
for all the details. Note that the [0]
part could indicate multiple simultaneous touches. I don't know how they are ordered, but touches[0]
could be first finger and touches[1]
could be second finger. The solution above worked for me because I only expect the user to use a stylus.
To get x and y co-ordinates try using below code
x1 = event.touches[0].pageX;
y1 = event.touches[0].pageY;
本文标签: javascriptTouch Event Not Returning Touch DataStack Overflow
版权声明:本文标题:javascript - Touch Event Not Returning Touch Data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744231848a2596374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论