Home >Web Front-end >HTML Tutorial >How to use js to implement long press function in html (code)

How to use js to implement long press function in html (code)

不言
不言Original
2018-08-17 17:59:554960browse

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(&#39;单击执行代码区&#39;);
            }            
            return false;
        };        
        function gtouchmove(){
            clearTimeout(timeOutEvent);
            timeOutEvent = 0;
            alert(&#39;单击未松开直接滑动的执行代码区,默认取消任何操作&#39;);
        };        
        function longPress(){
            timeOutEvent = 0;
            alert(&#39;长按执行代码区&#39;);
        }    </script>

Related recommendations:

How is the JS button flashing function implemented?


How to use html to implement positioning code example

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn