yangkaiyangyi/prombles

滑动时候警告:Unable to preventDefault inside passive event listener

Opened this issue · 0 comments

滑动时候警告:Unable to preventDefault inside passive event listener
touch事件-控制台打印如下警告

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. 
See https://www.chromestatus.com/features/5093566007214080

解决办法1:
在touch的事件监听方法上绑定第三个参数{ passive: false },
通过传递 passive 为 false 来明确告诉浏览器:事件处理程序调用 preventDefault 来阻止默认滑动行为。

elem.addEventListener(
  'touchstart',
  fn,
  { passive: false }
);

解决办法2:
在css全局样式
* { touch-action: pan-y; }
使用全局样式样式去掉