【转】原生js实现移动端h5长按事件


$("#target").on({    
        touchstart: function(e) {   
            // 长按事件触发    
            timeOutEvent = setTimeout(function() {    
                timeOutEvent = 0;    
                alert('你长按了');    
            }, 400);    
            //长按400毫秒     
            // e.preventDefault();      
        },    
        touchmove: function() {    
            clearTimeout(timeOutEvent);    
            timeOutEvent = 0;    
        },    
        touchend: function() {    
            clearTimeout(timeOutEvent);    
            if (timeOutEvent != 0) {    
                // 点击事件    
                // location.href = '/a/live-rooms.html';    
                alert('你点击了');    
            }    
            return false;    
        }    
    })  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM