美文网首页
H5实现安卓长按/抬起事件

H5实现安卓长按/抬起事件

作者: 岳小弟 | 来源:发表于2018-06-05 11:20 被阅读0次

    <!DOCTYPE html>
    <html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>长按</title>
    <style>
    body {
    -webkit-touch-callout: none !important;
    -webkit-overflow-scrolling: touch;
    }
    img,a{
    pointer-events: none;
    }
    .long{
    -webkit-user-select: none;
    }
    </style>
    <script src="jquery-3.0.0.min.js"></script> //当然也可以引入绝对路径
    <body>
    <div style="margin-left: 200px;margin-top: 100px"><button class="long" style="width:100px;height:100px; user-select: none;"></button></div>
    <div style="margin-top: 100px;margin-left: 100px"><span id="num" style="font-size: 100px;">5</span></div>
    <script>

    window.document.oncontextmenu = function (e) {
    e.preventDefault();
    };
    var $long = $('.long');
    var timer = null;
    $long.on('touchstart', function(){
    plus('#num');
    });
    $long.on('touchend', function(){
    clearTimeout(timer);
    });

    function plus(ele){
    var num = parseInt($(ele).text());
    $(ele).text(++num);
    timer = setTimeout(function(){
    plus(ele);
    }, 200);
    }
    </script>
    </body>
    </html>

    相关文章

      网友评论

          本文标题:H5实现安卓长按/抬起事件

          本文链接:https://www.haomeiwen.com/subject/gljpsftx.html