移動端長按事件——jquey例子
阿新 • • 發佈:2018-12-11
$("#target").on({ touchstart: function(e) { // 長按事件觸發 timeOutEvent = setTimeout(function() { timeOutEvent = 0; alert('你長按了'); }, 400); //長按400毫秒 // e.preventDefault(); }, touchmove: function() { clearTimeout(timeOutEvent); timeOutEvent = 0; }, touchend: function() { clearTimeout(timeOutEvent); if (timeOutEvent != 0) { // 點選事件 // location.href = '/a/live-rooms.html'; alert('你點選了'); } return false; } })
1.使用移動端事件,touchstart、touchmove、touchend來實現長按事件。
2.touchstart事件下,執行定時器,處理長按要做的操作。touchmove、touchend時清除定時器