500ms後に「開く」APIコマンドを使用してコンテキストメニューを開く簡単なロングタッチ機能を使用しました。メニューが開きます。しかし、 "touchend"ではメニューが消えます。私が "touchend"の前にコンテキストメニューをタッチすると、それだけが残ります。この種の行動を防ぐ方法はありますか?ソースコードから、DOMの異なる部分の「タッチスタート」だけがクローズイベントをトリガーする必要があります。タッチイベントを使用するときにメニューを閉じないようにする
コードは以下のように便利です。私のコンテクストメニューでは、trの代理人が必要ではなく、以下のtargetTr変数の使用方法を説明してください。
var mobDevice_onLongTouch,
mobDevice_touchTimer,
mobDevice_longPressDuration = 500; //length of time we want the user to touch before we do something
//handle long press on the datatable
var touchArea = document.querySelector("#table");
touchArea.addEventListener("touchstart", touchAreaTouchStart, false);
touchArea.addEventListener("touchend", touchAreaTouchEnd, false);
function touchAreaTouchStart(e) {
var targetTr = $(e.target).closest('tr');
mobDevice_touchTimer = setTimeout(function() { touchArea_onLongTouch(targetTr) }, mobDevice_longPressDuration)
};
function touchAreaTouchEnd(e) {
if (mobDevice_touchTimer) {
clearTimeout(mobDevice_touchTimer) //reset the clock
}
};
function touchArea_onLongTouch(target) {
$('#table').contextmenu('open', target);
};