如何在Chrome 69中以编程方式创建TouchEvent Zoom?

时间:2018-10-09 09:59:21

标签: javascript touch pinchzoom

我正在尝试以编程方式缩放图片。 https://jsbin.com/zaxogifino/1/edit?js,console,output

如何创建缩放事件?我尝试过

myElement = document.querySelector('#g2');
sendTouchEvent(247, 379, myElement, 'touchstart');
sendTouchEvent(317, 591, myElement, 'touchstart');

sendTouchEvent(257, 389, myElement, 'touchmove');
sendTouchEvent(307, 581, myElement, 'touchmove');

sendTouchEvent(267, 399, myElement, 'touchmove');
sendTouchEvent(297, 571, myElement, 'touchmove');

但是它不起作用。

function sendTouchEvent(x, y, element, eventType) {
  const touchObj = new Touch({
    identifier: Date.now(),
    target: element,
    clientX: x,
    clientY: y,
    pageX: x,
    pageY: y,
    screenX: x,
    screenY: y,
    radiusX: 25,
    radiusY: 25,
    rotationAngle: 0,
    force: 0.5,
  });

  const touchEvent = new TouchEvent(eventType, {
    cancelable: true,
    bubbles: true,
    touches: [touchObj],
    targetTouches: [],
    changedTouches: [touchObj],
    shiftKey: true,
  });

  element.dispatchEvent(touchEvent);
}

0 个答案:

没有答案