绑定事件的时候,如果pc与移动端都用,可以做一下,pc与移动端的兼容

来源:互联网 发布:寻找客户资料的软件 编辑:程序博客网 时间:2024/05/19 10:15

这里只谈及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){

        

        })



0 0
原创粉丝点击