Javascript touch事件实现
2012-03-13 20:28
330 查看
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title></title> <script type="text/javascript"> window.onload = function() { document.addEventListener("touchstart",touchStart, false); document.addEventListener("touchend",touchEnd, false); document.addEventListener("touchmove",touchMove, false); } function touchStart(event) { Ev= event || window.event; var touchPos = touchCoords(Ev); var eventx = document.getElementById("eventx"); eventx.value = touchPos.x; var eventy = document.getElementById("eventy"); eventy.value = touchPos.y; var textmsg = document.getElementById("eventmsg"); textmsg.value = "down"; } function touchEnd(event) { var textmsg = document.getElementById("eventmsg"); textmsg.value = "up"; } function touchMove(event) { Ev= event || window.event; var touchPos = touchCoords(Ev); var eventx = document.getElementById("eventx"); eventx.value = touchPos.x; var eventy = document.getElementById("eventy"); eventy.value = touchPos.y; var textmsg = document.getElementById("eventmsg"); textmsg.value = "move"; } function touchCoords(ev) { if(ev.pageX || ev.pageY){ return {x:ev.pageX, y:ev.pageY}; } return{ x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, y:ev.clientY + document.body.scrollTop - document.body.clientTop }; } </script> </head> <body> <table> <tr> <td> <table> <tr> <td><input type="text" id="eventmsg" size=10></input></td> <td><input type="text" id="eventx" size=10></input></td> <td><input type="text" id="eventy" size=10></input></td> </tr> </table> </td> </tr> </table> </div> </body> </html>
相关文章推荐
- 传统javascript事件模型实现观察者模式
- javascript的事件触发器介绍的实现
- silverlight线程与基于事件驱动javascript引擎(实现轨迹回放功能)
- javascript touch事件
- 移动端Touch事件与H5-Canvas像素点检测实现刮刮乐
- JavaScript实现事件的中断传播和行为阻止方法示例
- 一段实现HTML页面内定期触发事件的JavaScript代码
- javascript某标签的鼠标滚动事件取消效果或实现其他自定义效果
- JavaScript实现为事件句柄绑定监听函数的方法分析
- JavaScript实现禁用键盘和鼠标的点击事件
- JavaScript实现自定义事件
- javascript滚动栏响应鼠标滑轮的实现上下滚动事件
- JavaScript调用Activex控件的事件的实现方法
- 50、JavaScript里面,自定义事件的简单实现(事件队列的简单实现)
- touch gesture 事件在移动端的简单实现
- html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove
- 详解javascript实现自定义事件
- javascript实现Observer模式来管理多个事件回调
- javascript阻止scroll事件多次执行的思路及实现
- JavaScript实现响应事件实例