HTML5 pointermove/touchmove not working in Microsoft Edge

删除回忆录丶 提交于 2019-12-24 14:14:22

问题


I'm working on something which is more or less a drawing app. I need to support Microsoft Edge and there's the problem. As soon as you want to catch the touchmove or pointermove event, Edge tries to scroll (even if it's not possible). Here's an example. Just try to draw something there (touch/pen), mouse works perfectly even in Edge. In every other browser (except maybe IE) it works very well.

I have no idea why IE is ignoring the preventDefault() function. Has someone an idea?

Sample: https://jsfiddle.net/ryqagkeb/

Actually doesn't work with my Surface Pro & Surface Pen on Chrome and Edge.

canvas = document.getElementsByTagName('canvas')[0];
ctx = canvas.getContext('2d');
start = 0;
canvas.onpointerdown = function(evt) {
    start = 1;
}

canvas.onpointermove = function(evt) {
    if(start) {
        ctx.fillRect(evt.clientX, evt.clientY, 5,5);
    }
}

canvas.onpointerup = function(evt) {
    start = 0;
}

回答1:


So I think I've found the solution myself and posting it now because I think it's pretty helpful. It seems the CSS property "touch-action" can solve the problem.

Setting:

canvas {
    touch-action: none;
}

It seems like it fixes the problem.



来源:https://stackoverflow.com/questions/49299496/html5-pointermove-touchmove-not-working-in-microsoft-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!