Touch Event

转自:      http://hi.baidu.com/masaiui/item/971775e8b316238bc10d754b

参考: http://hedgehogking.com/?p=556

 

 

 

最近在开发手机端WEB2.0网站。转载一个留着备用

touchstart:触摸开始的时候触发

touchmove:手指在屏幕上滑动的时候触发

touchend:触摸结束的时候触发

而每个触摸事件都包括了三个触摸列表,每个列表里包含了对应的一系列触摸点(用来实现多点触控):

touches:当前位于屏幕上的所有手指的列表。

targetTouches:位于当前DOM元素上手指的列表。

changedTouches:涉及当前事件手指的列表。

每个触摸点由包含了如下触摸信息(常用):

identifier:一个数值,唯一标识触摸会话(touch session)中的当前手指。一般为从0开始的流水号(android4.1,uc)

target:DOM元素,是动作所针对的目标。

pageX/pageX/clientX/clientY/screenX/screenY:一个数值,动作在屏幕上发生的位置(page包含滚动距离,client不包含滚动距离,screen则以屏幕为基准)。 

radiusX/radiusY/rotationAngle:画出大约相当于手指形状的椭圆形,分别为椭圆形的两个半径和旋转角度。初步测试浏览器不支持,好在功能不常用,欢迎大家反馈。

 

/*单指拖动*/
var obj = document.getElementById('id');
obj.addEventListener('touchmove', function(event) {
     // 如果这个元素的位置内只有一个手指的话
    if (event.targetTouches.length == 1) {
     event.preventDefault();// 阻止浏览器默认事件,重要 
        var touch = event.targetTouches[0];
        // 把元素放在手指所在的位置
        obj.style.left = touch.pageX-50 + 'px';
        obj.style.top = touch.pageY-50 + 'px';
        }
}, false);

 

 

 

转载于:https://www.cnblogs.com/BigIdiot/p/3170093.html

static int UI_MainThread(void* arg)//线程入口函数 { int ret = 0; WM_HWIN handle = 0; //basic gui init ret = GUI_Init(); if(ret < 0) { Error("GUI Init Failed\n"); return -1; } //user config init WM_MULTIBUF_Enable(1); GUI_AA_SetFactor(4); GUI_UC_EnableBIDI(1); GUI_UC_SetEncodeUTF8(); //first window handle = UI_WindowHomeCreate(WM_HBKWIN); UI_HomeWindowSet(handle); //main loop for paint and display while(1) { GUI_Delay(10); } return 1; } /****************************************************************************** function : touch event process thread arguments : thread info return : fail < 0,ok >= 0 ******************************************************************************/ static int UI_TouchThread(void* arg) { int ret = 0; int32_t touch_fb = -1; WM_MESSAGE Msg; struct input_event touch_event; TOUCH_DATA touch_info; int first_touch = 0; touch_fb = open("/dev/input/event0", O_RDONLY); if(touch_fb < 0) { Error("open touch dev failed = %d\n", touch_fb ); return -1; } Log(UI_LOG_NORMAL, "touch event open ok\n"); while(1) { ret = read(touch_fb, &touch_event, sizeof(touch_event)); if(ret != sizeof(touch_event)) { Error("no touch\n"); continue; } //Log(UI_LOG_NORMAL, "touch info:%d, %d, %d\n", // touch_event.type, touch_event.code, touch_event.value); switch(touch_event.type) { case EV_ABS: if (ABS_X == touch_event.code) { touch_info.x = touch_event.value; } else if (ABS_Y == touch_event.code) { touch_info.y = touch_event.value; if(UI_HomeWindowGet() != UI_ActiveWindowGet()) { if (touch_info.y<=UI_WINDOW_CHILD_Y) { touch_info.y = 0; } else { touch_info.y -= UI_WINDOW_CHILD_Y; } } } break; case EV_KEY: if (BTN_TOUCH == touch_event.code) { if (TOUCH_DOWN == touch_event.value) { touch_info.type = TOUCH_DOWN; if (!first_touch) { first_touch = 1; ui_buzzer_alert(UI_BUZZER_ALERT_TOUCH); ui_power_notify(UI_POWER_NOTIFY_RESET); } } else if (TOUCH_UP == touch_event.value) { touch_info.type = TOUCH_UP; first_touch = 0; } } break; case EV_SYN: //set pose UI_TouchDataSet(&touch_info); //Log(UI_LOG_NOTICE, "touch x = %3d,y = %3d,t = %d to wm = %d\n", //touch_info.x, touch_info.y, touch_info.type, UI_ActiveWindowGet()); //send msg to active window Msg.MsgId = WM_USER_TOUCH_UP+touch_info.type; Msg.Data.v = 0x00; if (UI_ActiveWindowGet()) { WM_SendMessage(UI_ActiveWindowGet(), &Msg); } break; default: break; } } return 0; }
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值