How can I catch tap on a touch phone?

Hi. Made a mobile menu to close when clicking outside it and outside its children.

$(document).on('click', function (e) {
var container2 = $(".mobile-menu");
if (container2.has(e.target).length === 0){
$('.mobile-menu').addClass('menu-closed');
$('.mobile-menu').removeClass('menu-open').fadeOut(500);
$('body').removeClass('ovrfl');}});

On the desktop everything is cool works as it should, but no mouseup, tried to attribute to "tap" instead of "mouseup", but something isn't working.

"click" use is not an option in my case. Who-thread prompt as you write the code with the event "tap" or something? If the type was tap out diva, you to menu add class 'menu-closed'???
June 10th 19 at 15:07
1 answer
June 10th 19 at 15:09
Solution
<canvas id="canvas" width="600" height="600" style="border:1px solid black;">
 Your browser does not support the canvas element.
</canvas>
<br / >
<button onclick="startup()">Initialize</button>
<br / >
Log: <pre id="log" style="border: 1px solid #ccc;"></pre>

function startup() {
 var el = document.getElementsByTagName("canvas")[0];
 el.addEventListener("touchstart", handleStart, false);
 el.addEventListener("touchend", handleEnd, false);
 el.addEventListener("touchcancel", handleCancel, false);
 el.addEventListener("touchmove", handleMove, false);
log("initialized.");
}


Useful links:
https://developer.apple.com/library/content/docume...
https://developer.mozilla.org/en-US/docs/Web/API/T... (or in Russian)
tutorials.jenkov.com/responsive-mobile-friendly-we...
www.stucox.com/blog/you-cant-detect-a-touchscreen
www.javascriptkit.com/javatutors/touchevents.shtml
https://github.com/pukhalski/tap

Find more questions by tags jQueryJavaScript