jQuery觸屏外掛程式:Tap 代碼

來源:互聯網
上載者:User

標籤:c   a   http   tar   ext   get   

jQuery觸屏外掛程式:Tap,使用方法非常簡單,例:
$("#domid").tap(function(){
alert("You tapped me! -- by"+this.innerText);
});
依賴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);
21
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
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.