触摸事件--兼容不同浏览器及不同IE版本
2016-01-06 15:07
681 查看
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="viewport" content="width=device-width,initial-scale=1"> <style type="text/css"> /* Direct all pointer events to JavaScript code. */ .touch{ -ms-touch-action: none; /* set for IE */ touch-action: none; /* set for Edge */ } </style> </head> <body> <h1>Touch event compatible with different browser and IE version.</h1> <br/> <div id="monitor"> Coordinate: X-0, Y-0 </div> <div id="holder" class="touch" style="height:200px;background-color:rgb(103, 195, 215)"> Moving your finger on this div block, your will see coordinate on the above changed as your moving. </div> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript"> window.onload = function() { if(window.PointerEvent) //IE 11 & Edge { $('#holder').on('pointermove', printcoordinate); } else if(window.MSPointerEvent) //IE10 { $('#holder').on('MSPointerMove', printcoordinate); } else //Chrome, Safari { $('#holder').on('touchmove', printcoordinate); } function printcoordinate(e) { var pointerEnabled = window.PointerEvent || window.MSPointerEvent; var touches = pointerEnabled ? e.originalEvent : e.originalEvent.touches[0]; $('#monitor').html("Coordinate: X-" + touches.pageX + ", Y-" + touches.pageY); } } </script> </body> </html>
参考:
https://msdn.microsoft.com/en-us/library/windows/apps/hh465895.aspx https://blogs.msdn.microsoft.com/ie/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers/ https://msdn.microsoft.com/en-us/library/hh972895(v=vs.85).aspx
相关文章推荐
- 手机页面禁止页面拖动
- openlayers3 pointermove onmousemove 显示feature信息
- #734 – 在触摸事件中识别不同的手指(Recognizing Different Fingers in Touch Event Handlers)
- javascript 手机手势动作touch触屏原理分析,h5触摸下拉刷新上拉加载数据原理
- 移动端使用touchstart,touchmove,touchend实现图片轮播
- touch事件兼容性处理
- 大话Android Touch事件传递机制
- 微信中body的touchmove事件(下拉显示网址)影响元素的touchmove事件的解决方法
- touchstart, touchmove, touchend, mousedown, mousemove, mouseup, 手机端和pc端点击及触摸事件
- 新增端口
- 数据库收不到消息
- 源码推荐(01.06B):类似QQ音乐界面,相册多选 / 相机连拍
- Ubuntu “size mismatch” apt-get install
- ROS安装USB摄像头
- 莫大的福气
- 实现手机访问,自动跳转网站手机版
- 资源下载站
- Android:自动完成文本框(AutoCompleteTextView、MultiAutoCompleteTextView )
- System.getProperty(parameter)
- OpenSessionInViewFilter 的配置及作用