Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
105 views
in Technique[技术] by (71.8m points)

javascript - 您如何调用touchcancel事件(How do you invoke a touchcancel event)

I'm using a touchstart event to dispatch a simulated key press, while this does work, it only works once as dispatchEvent no longer becomes responsive.

(我正在使用touchstart事件来调度模拟的按键,尽管它确实起作用,但由于dispatchEvent不再具有响应性,因此仅起作用一次。)

Until eg (in touch screen mode) clicking outside the document and pressing the button again.

(直到(例如,在触摸屏模式下)在文档外部单击并再次按下按钮。)

After doing some research I kinda came to a conclusion that if I invoked a touchcancel right after a touchstart it would be a unorthodox but probable solution.

(经过一些研究,我得出一个结论:如果我在一次触摸启动后立即调用一个触摸取消,那将是一个不合常规但可能的解决方案。)

touch cancel .

(触摸取消 。)

I was hoping someone could provide some way of invoking this touchCancel event by some conventional means or perhaps provide some insight about this behavior.

(我希望有人可以通过一些常规方法提供某种方式来调用此touchCancel事件,或者也许可以对此行为提供一些见识。)

 var kEvent = document.createEvent("HTMLEvents");
 var obj = document.getElementById('left_button');

 obj.addEventListener('touchstart', function(event) {  

    kEvent.initEvent( "keydown", true, true);
    kEvent.keyCode = 37;//left key
    obj.dispatchEvent(kEvent);

 }, true);
  ask by Eric Kroeger translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...