$.fn.longPress = function(fn) { var timeout = undefined; var $this = this; for(var i = 0;i<$this.length;i++){ $this[i].addEventListener('touchstart', function(event) { timeout = the setTimeout (Fn, 800); // long press time exceeds 800ms, the method is performed incoming }, to false ); $this[i].addEventListener('touchend', function(event) { the clearTimeout (timeout); // long press time is less than 800ms, the method does not perform the incoming }, to false ); } }
To add this code first, then call:
$('.object').longPress(function(){ //do something... });