How to use the “Long touch” event?
■ Summary
- If you use the "touchstart" and "touchend" event, you can create the "long touch" event.
- If you use the "touchstart" and "touchend" event, you can create the "long touch" event.
var touchtimer,
flagLock,
touchduration = 500;
var onlongtouch = function() {
alert("Long Touch!!");
};
function touchstart(e) {
e.preventDefault();
if(flagLock){
return;
}
touchtimer = setTimeout(onlongtouch, touchduration);
flagLock = true;
}
function touchend() {
if (touchtimer){
clearTimeout(touchtimer);
flagLock = false;
}
}
window.onload = function () {
window.addEventListener("touchstart", touchstart, false);
window.addEventListener("touchend", touchend, false);
};