The content of this article is about how to use js to implement the long press function (code) in HTML. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
//The following is the js code, just copy and paste it One judgment is long-pressed to execute the second judgment click to execute
<script> var timeOutEvent=0; function gtouchstart(){ timeOutEvent = setTimeout(longPress(),500); return false; //单击开始计时 500代表0.5秒 //如果longPress()需要传参得写成下面注释中的代码 //timeOutEvent = setTimeout(function(){ longPress(url);},500); }; function gtouchend(){ clearTimeout(timeOutEvent); if(timeOutEvent!=0){ alert('单击执行代码区'); } return false; }; function gtouchmove(){ clearTimeout(timeOutEvent); timeOutEvent = 0; alert('单击未松开直接滑动的执行代码区,默认取消任何操作'); }; function longPress(){ timeOutEvent = 0; alert('长按执行代码区'); } </script>
Related recommendations:
How is the JS button flashing function implemented? How to use html to implement positioning code exampleThe above is the detailed content of How to use js to implement long press function in html (code). For more information, please follow other related articles on the PHP Chinese website!