Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 离开画布jQuery时不触发touchleave_Javascript_Jquery_Html_Canvas - Fatal编程技术网

Javascript 离开画布jQuery时不触发touchleave

Javascript 离开画布jQuery时不触发touchleave,javascript,jquery,html,canvas,Javascript,Jquery,Html,Canvas,我基本上是用它来让我的图像在画布上拖动 我正在尝试添加触摸事件,除touchleave外,所有触摸事件都正常工作。当用户试图将图像拖到画布外时,touchleave事件似乎没有触发。是否有其他触摸事件可用于此目的?请参阅。在这里,它们实际上是触发触摸EVNT的鼠标事件。这可能对你有帮助 touchstart – to toggle drawing mode “on” touchend – to toggle drawing mode “off” touchmove – to track fing

我基本上是用它来让我的图像在画布上拖动

我正在尝试添加触摸事件,除touchleave外,所有触摸事件都正常工作。当用户试图将图像拖到画布外时,touchleave事件似乎没有触发。是否有其他触摸事件可用于此目的?

请参阅。在这里,它们实际上是触发触摸EVNT的鼠标事件。这可能对你有帮助

touchstart – to toggle drawing mode “on”
touchend – to toggle drawing mode “off”
touchmove – to track finger position, used in drawing


// Set up touch events for mobile, etc
canvas.addEventListener("touchstart", function (e) {
        mousePos = getTouchPos(canvas, e);
  var touch = e.touches[0];
  var mouseEvent = new MouseEvent("mousedown", {
    clientX: touch.clientX,
    clientY: touch.clientY
  });
  canvas.dispatchEvent(mouseEvent);
}, false);
canvas.addEventListener("touchend", function (e) {
  var mouseEvent = new MouseEvent("mouseup", {});
  canvas.dispatchEvent(mouseEvent);
}, false);
canvas.addEventListener("touchmove", function (e) {
  var touch = e.touches[0];
  var mouseEvent = new MouseEvent("mousemove", {
    clientX: touch.clientX,
    clientY: touch.clientY
  });
  canvas.dispatchEvent(mouseEvent);
}, false);

// Get the position of a touch relative to the canvas
function getTouchPos(canvasDom, touchEvent) {
  var rect = canvasDom.getBoundingClientRect();
  return {
    x: touchEvent.touches[0].clientX - rect.left,
    y: touchEvent.touches[0].clientY - rect.top
  };
}

我已经绘制了这些触摸事件。我只是没有鼠标的触摸功能