zoukankan      html  css  js  c++  java
  • 移动长按事件

    <!DOCTYPE html>  
    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <title>长按</title>  
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />  
    <meta name="apple-touch-fullscreen" content="yes">  
    <meta name="apple-mobile-web-app-capable" content="yes" />  
    <link href="css/travelstyle.css" rel="stylesheet" type="text/css" />  
      
    </head>  
    <body id="body_id" >  
    <div style="100%;">  
    <div style="100%; height:100px; " ontouchstart="gtouchstart()" ontouchmove="gtouchmove()" ontouchend="gtouchend()">长按我</div>   
    </div>  
    <script>  
    var timeOutEvent=0;//定时器   
    //开始按   
    function gtouchstart(){   
        timeOutEvent = setTimeout("longPress()",500);//这里设置定时器,定义长按500毫秒触发长按事件,时间可以自己改,个人感觉500毫秒非常合适   
        return false;   
    };   
    //手释放,如果在500毫秒内就释放,则取消长按事件,此时可以执行onclick应该执行的事件   
    function gtouchend(){   
        clearTimeout(timeOutEvent);//清除定时器   
        if(timeOutEvent!=0){   
            //这里写要执行的内容(尤如onclick事件)   
            alert("你这是点击,不是长按");   
        }   
        return false;   
    };   
    //如果手指有移动,则取消所有事件,此时说明用户只是要移动而不是长按   
    function gtouchmove(){   
        clearTimeout(timeOutEvent);//清除定时器   
        timeOutEvent = 0;   
          
    };   
       
    //真正长按后应该执行的内容   
    function longPress(){   
        timeOutEvent = 0;   
        //执行长按要执行的内容,如弹出菜单   
        alert("长按事件触发发");   
    }   
      
    </script>  
    </body>  
    </html>  
     
  • 相关阅读:
    LeetCode59 Spiral Matrix II
    LeetCode58 Length of Last Word
    LeetCode54 Spiral Matrix
    LeetCode63 Unique Paths II
    LeetCode62 Unique Paths
    LeetCode55 Jump Game
    网易2017年校招笔试题 最大的奇约数
    Codeforces Round #119 (Div. 2)
    Codeforces Round #118 (Div. 2)
    2016 MIPT Pre-Finals Workshop Taiwan NTU Contest
  • 原文地址:https://www.cnblogs.com/feiwenstyle/p/10184015.html
Copyright © 2011-2022 走看看