jquery Touch Screen plugin: Tap, the use of the method is very simple, for example:
$ ("#domid"). Tap (function () {
Alert ("You tapped me! -by "+this.innertext");
});
Rely on jquery 1.7+
01
$.fn.tap = function (fn) {
02
var collection = this,
03
Istouch = "Ontouchend" in Document.createelement ("div"),
04
Tstart = Istouch? "Touchstart": "MouseDown",
05
Tmove = Istouch? "Touchmove": "MouseMove",
06
tend = Istouch? "Touchend": "MouseUp",
07
Tcancel = Istouch? "Touchcancel": "Mouseout";
08
Collection.each (function () {
09
var i = {};
10
I.target = this;
11
$ (I.target). On (Tstart,function (e) {
12
var p = "Touches" in e? E.touches[0]: (Istouch window.event.touches[0]: window.event);
13
I.startx = P.clientx;
14
I.starty = P.clienty;
15
I.endx = P.clientx;
16
I.endy = P.clienty;
17
I.starttime = + new Date;
18
});
19
$ (I.target). On (Tmove,function (e) {
20
var p = "Touches" in e? E.touches[0]: (Istouch window.event.touches[0]: window.event);
21st
I.endx = P.clientx;
22
I.endy = P.clienty;
23
});
24
$ (I.target). On (Tend,function (e) {
25
if ((+ new Date)-i.starttime<300) {
26
if (Math.Abs (I.ENDX-I.STARTX) +math.abs (i.endy-i.starty) <20) {
27
var e = e | | window.event;
28
E.preventdefault ();
29
Fn.call (I.target);
30
http://www.huiyi8.com/biaoqian/taobao/}
31
}
32
I.starttime = undefined;
33
I.startx = undefined;
34
I.starty = undefined;
35
I.endx = undefined;
36
I.endy = undefined;
37
});
38
});
39
return collection;
40
}