H5页面监听长按事件

H5页面监听长按事件
        var timeOutEvent;
        
        $(document).on("touchstart","body img",function(e){           
                    var that = this;
                    timeOutEvent = setTimeout("longPress()",500);//500设置时间
                    picUrl = $(that).attr('src');                        
                     e.preventDefault(); 
        })
        $(document).on("touchmove","body img",function(e){
            clearTimeout(timeOutEvent); 
            timeOutEvent = 0;
        })
        $(document).on("touchend","body img",function(e){
            clearTimeout(timeOutEvent);
            if(timeOutEvent!=0){ 
                //alert("你这是点击,不是长按"); 
            } 
            return false;
        })
        
        function longPress(){ 
            timeOutEvent = 0; 
            //alert("长按事件触发发");    
        } 

猜你喜欢

转载自blog.csdn.net/u012011360/article/details/106219568