Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

添加tap Off 方法;

  • Loading branch information...
commit 8aa4805b1b915191cfbcde76b10861a7bdd3c671 1 parent 4b69eda
guankaishe authored
Showing with 40 additions and 5 deletions.
  1. +1 −1  README.md
  2. +39 −4 fastap.js
2  README.md
View
@@ -1,4 +1,4 @@
fastap
======
-Simple, fast & small Fastclick module, use touch events simulate click on touch device.
+Simple, fast & small Fastclick Zepto/JQuery plugin, use touch events simulate click on touch device.
43 fastap.js
View
@@ -1,10 +1,12 @@
+var events = [];
+
/**
* 覆盖zepto默认的tap
**/
$.fn.tap = function(handler) {
- var $con = $(this);
+ var $con = this;
- $con.on('touchstart', function(event) {
+ function tapHandler (event) {
var $tar = $(event.target);
if (!$tar) return;
@@ -14,7 +16,7 @@ $.fn.tap = function(handler) {
var isSroll = false,
isEnd = false,
isFeed = false,
- delay = 20;
+ delay = 50;
function scrollHandler(e) {
isSroll = true;
@@ -31,7 +33,7 @@ $.fn.tap = function(handler) {
}
setTimeout(function() {
isFeed && handler && handler(event);
- }, 30);
+ }, delay + 10);
}
$con.on('touchmove', scrollHandler);
$tar.on('touchend', endHandler);
@@ -39,5 +41,38 @@ $.fn.tap = function(handler) {
setTimeout(function() {
isFeed = true;
}, delay);
+ }
+ events.push({
+ $el: this,
+ listener: tapHandler,
+ handler: handler
});
+ $con.on('touchstart', tapHandler);
};
+
+/**
+ * 取消监听tap事件(必需为覆盖zepto的tap事件)
+ **/
+$.fn.tapOff = function (handler) {
+
+ for (var i = 0; i < events.length; i ++) {
+ var evtObj = events[i];
+ isMatched = false;
+
+ if (evtObj) {
+ this.each(function (index, el) {
+ evtObj.$el.each(function (index, target) {
+ if (target == el) {
+ isMatched = true;
+ return true;
+ }
+ });
+ if (isMatched) return true;
+ });
+ if (handler == evtObj.handler && isMatched) {
+ this.off('touchstart', evtObj.listener);
+ events[i] = null;
+ }
+ }
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.