您的位置:首页 > 移动开发

绑定事件的时候,如果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){

        

        })
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息