关于手触

在krpano上看到一段关于手触响应的代码

 1 function imagebar_onTouchStart(a) {
2 a.preventDefault();
3 imagebar_touch_x = a.changedTouches[0].pageX;
4 imagebar_touch_y = a.changedTouches[0].pageY
5 }
6 function imagebar_onTouchMove(a) {
7 a.preventDefault()
8 }
9 function imagebar_onTouchEnd(a) {
10 var b = a.changedTouches[0].pageX - imagebar_touch_x;
11 if (a.changedTouches[0].pageY - imagebar_touch_y > 100) {
12 a.preventDefault();
13 showImagebarPano()
14 } else if (b < -100 || b > 100) {
15 a.preventDefault();
16 nextRandomImageBar()
17 }
18 }
19 function touch_inits() {
20 var a = navigator.platform.toLowerCase();
21 if (a.indexOf("iphone") >= 0 || a.indexOf("ipod") >= 0 || a.indexOf("ipad") >= 0) try {
22 var b = document.getElementById("krpano_imagebar");
23 if (b) {
24 b.addEventListener("touchstart", imagebar_onTouchStart, true);
25 b.addEventListener("touchmove", imagebar_onTouchMove, true);
26 b.addEventListener("touchend", imagebar_onTouchEnd, true)
27 }
28 } catch (c) {}
29 }

 

其它参考:http://www.cnblogs.com/pifoo/archive/2011/05/23/webkit-touch-event-1.html

苹果官方参考:http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebcontent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW1

posted @ 2011-12-09 11:17  z s k  阅读(255)  评论(0编辑  收藏  举报