绑定事件的时候,如果pc与移动端都用,可以做一下,pc与移动端的兼容
2016-05-26 09:28
281 查看
这里只谈及PC端的mousedown mousemove mouseup事件 与 移动端的touchstart touchmove touchend事件
var hastouch = 'ontouchstart' in window?true:false, //判断是否为移动端
tapstart = hastouch?'touchstart':'mousedown',
tapmove = hastouch?'touchmove':'mousemove',
tapend = hastouch?'touchend':'mouseup';
然后就可以绑定事件了,
例:ctx.addEventListener(tapstart,function(e){
})
var hastouch = 'ontouchstart' in window?true:false, //判断是否为移动端
tapstart = hastouch?'touchstart':'mousedown',
tapmove = hastouch?'touchmove':'mousemove',
tapend = hastouch?'touchend':'mouseup';
然后就可以绑定事件了,
例:ctx.addEventListener(tapstart,function(e){
})
相关文章推荐
- 在 Linux 中如何移动文件
- PowerShell移动目录中指定文件的方法(非全部文件)
- 鼠标触发移动的分层菜单 层菜单moveMenu
- 基于Android实现随手指移动的ImageView
- php实现复制移动文件的方法
- javascript实现图片跟随鼠标移动效果的方法
- JavaScript Select和Option列表元素上下左右移动
- JavaScript代码实现左右上下自动晃动自动移动
- JS实现网页游戏中滑块响应鼠标点击移动效果
- JS+CSS实现分类动态选择及移动功能效果代码
- 详解jQuery移动页面开发中的ui-grid网格布局使用
- jquery移动点击的项目到列表最顶端的方法
- 基于jquery实现select选择框内容左右移动添加删除代码分享
- jquery实现select选择框内容左右移动代码分享
- 使用jQuery mobile库检测url绝对地址和相对地址的方法
- jQuery移动web开发之页面跳转和加载外部页面的实现
- JQuery移动页面开发之屏幕方向改变与滚屏的实现
- 浅析jQuery Mobile的初始化事件
- C#中无边框窗体移动的简单实例
- c#文件的复制,移动,创建(实例代码)