jq 觸摸長按觸發事件

//長按事件觸發
$.fn.longPress = function(fn) {

    var timeout = undefined;
    var $this = this;
    for(var i = 0; i < $this.length; i++) {
      (function(target) {
        var timeout;
        target.addEventListener('touchstart', function(event) {
          timeout = setTimeout(function() {
            //fn.apply(target);
            fn(event);
          }, 500);
        }, false);
        target.addEventListener('touchend', function(event) {
          clearTimeout(timeout);
        }, false);
      })($this[i]);
    }
}
//調用事件 $(
"#id").longPress(function(e){ alert("adfs"); });
相關文章
相關標籤/搜索