[英]Why does touchmove not fire on html canvas?
I'm using an angular app, where the user has a canvas, and can draw rectangles on that canvas. 我正在使用一个有角度的应用程序,其中用户有一个画布,并且可以在该画布上绘制矩形。
My touchstart and touchend are firing, but touchmove is not. 我的touchstart和touchend正在触发,但touchmove不是。 I'm not sure if I'm not understanding how touchmove works.
我不确定我是否不了解touchmove的工作原理。 I was assuming it would be equivalent to mousemove.
我以为它等同于mousemove。
self.canvas.addEventListener('touchmove', (e) => { self.touchMove(e); });
self.canvas.addEventListener('touchstart', (e) => { self.touchStart(e); }); // touch down event
self.canvas.addEventListener('touchend', (e) => { self.touchEnd(e); }); //
touchStart(e) {
e.preventDefault();
const self = this;
const activeTag = self.TagService.activeTags[0];
this.canvasState.doTouchStart(e, activeTag, (shape) => {
self.selection = shape;
});
}
touchEnd(e) {
const self = this;
// console.log(this);//is the controller
const activeTag = self.TagService.activeTags[0];
self.canvasState.doTouchEnd(e, activeTag, function doTouchUp(shape) {
self.selection = shape;
self.addShape(shape);
// console.log(self.shapes);
});
}
touchmove(e) {
e.preventDefault();
console.log("HERE HERE HERE");
const self = this;
const activeTag = self.TagService.activeTags[0];
this.canvasState.doTouchMove(e, activeTag, (shape) => {
let len = self.shapes.length;
self.addShape(shape);
let len2 = self.shapes.length;
if (len2 - len === 1) {
self.draw();
self.shapes.splice(-1, 1);
}
});
}
The touchstart and touchend work, but touch move never fires. touchstart和touchend可以工作,但是touch move永远不会触发。 I can never get the console output.
我永远无法获得控制台输出。
Edit: I changed the first line to be touchmove
, as there was touchMove and touchmove (typo), but that still does not fire the touchmove. 编辑:我将第一行更改为
touchmove
,因为存在touchMove和touchmove(典型),但是仍然不能触发touchmove。 Also, I get Ignored attempt to cancel a touchstart event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.
另外,我被
Ignored attempt to cancel a touchstart event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.
warning when I try to draw something down. 警告,当我尝试放下一些东西。 This is really strange, because I tried the same thing in a non-angular app (Very simple canvas interactions), and I didn't get that error.
这真的很奇怪,因为我在非角度应用程序中尝试了相同的操作(非常简单的画布交互),但没有得到该错误。 It blocked me from scrolling, and instead drew stuff on the canvas.
它阻止了我滚动,而是在画布上画了东西。
If you review your code, when you add a listener in this line: 如果您查看代码,则在此行中添加侦听器时:
self.canvas.addEventListener('touchmove', (e) => { self.touchMove(e); });
you're calling the function self.touchMove(e)
and more below at the code you're declaring your function as touchmove(e)
, Here is a great library that it helps you to handle touch events Hammerjs 您在代码中将函数
self.touchMove(e)
以及下面的代码声明为touchmove(e)
,以下是一个很棒的库,它可以帮助您处理触摸事件Hammerjs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.