The first method: this example I do not get the current long press element;
$.fn.longpress =functionFN) {var timeout =Undefinedvar $this = this; for (var i = 0;i<$this.length;i++" {$this[i].addeventlistener (function (event) { Timeout = setTimeout (FN, 800); //long press time more than 800ms, then execute the incoming method}, false); $this[i].addeventlistener ( ' Touchend ', function (event) {clearTimeout ( Timeout); //long press time less than 800MS, will not execute the incoming method}, false); }}
Call:
$(‘.object‘).longPress(function(){ //do something...});
The second method : This method can get to the current element;
var Timeoutevent=0,cardid;
$ (". Card-list li"). On ({
Touchstart:function (e) {
var = this;
Timeoutevent = SetTimeout (function () {
Long Press Trigger Event
timeoutevent = 0;
Alert (' I'm in Long press ');
},800);
E.preventdefault ();
},
Touchmove:function () {
Cleartimeout (timeoutevent);
timeoutevent = 0;
},
Touchend:function () {
Cleartimeout (timeoutevent);
return false;
}
})
Mobile End Long Press event