技术笔记
jquery手机端屏蔽图片长按选择
 moons   2020-07-19 21:57:26   128
专栏分类: javascript

<script>
        var timeOutEvent=0;
        $(function(){
            $("img").on({
                touchstart: function(e){
                    timeOutEvent = setTimeout("longPress()",500);
                    e.preventDefault();
                },
                touchmove: function(){
                    clearTimeout(timeOutEvent); 
                    timeOutEvent = 0; 
                },
                touchend: function(){
                    clearTimeout(timeOutEvent);
                    if(timeOutEvent!=0){ 
                        alert("你这是点击,不是长按"); 
                    } 
                    return false; 
                }
            })
        });
        function longPress(){ 
            timeOutEvent = 0; 
            alert("长按事件触发发"); 
        } 
</script>
Copyright © mos360.cn By Moons Soft Studio 百度统计