createjs在windows触摸屏上用touch(解决部分设备无法监听move事件的bug)

  • 内容
  • 评论
  • 相关

记得几年前有个童鞋问我,他们给学校的window按压屏无法使用move类型的事件,我帮他解决了。当初认为这种需求是小众需求,就没有写在博客里,直到最近我也遇到了这个需求,那么今天我就把代码直接分享出来。

//windows触摸屏上用touch
createjs.Touch.enable = function(stage, singleTouch, allowDefault) {
  if (stage.__touch) { return true; }
  stage.__touch = {pointers:{}, multitouch:!singleTouch, preventDefault:!allowDefault, count:0};
  createjs.Touch._IOS_enable(stage);
  return true;
};
createjs.Touch.enable(stage);

代码很少也很简单,我来讲下原理,createjs开启touch事件会判断设备,windows下是不会touch的,因为常理来说windows下用的是鼠标而不是触摸屏,但是很多教室展厅的设备是用windows的,所以还是需要在windows下使用touch。然后根据原理,我重写了这个方法,使其在任何时候都可以开启touch。这里的_IOS_enable写着是IOS,实际上安卓等移动端也可以判断。

QQ图片20230505193037.png

评论

0条评论

发表评论

电子邮件地址不会被公开。