警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件(Added non-passive event listener to a scroll-blocking '
Posted zzsdream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件(Added non-passive event listener to a scroll-blocking '相关的知识,希望对你有一定的参考价值。
var passiveEvent = false; try { var opts = Object.defineProperty({}, ‘passive‘, { get: function () { passiveEvent = true; } }); window.addEventListener("test", null, opts); } catch (e) { } // in my case I need both passive and capture set to true, change as you need it. passiveEvent = passiveEvent ? { capture: true, passive: true } : true; //if you need to handle mouse wheel scroll var supportedWheelEvent: string = "onwheel" in htmlDivElement.prototype ? "wheel" : document.onmousewheel !== undefined ? "mousewheel" : "DOMMouseScroll";
使用:
elementRef.addEventListener("touchstart", handler, passiveEvent);
以上是关于警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件(Added non-passive event listener to a scroll-blocking '的主要内容,如果未能解决你的问题,请参考以下文章
[Violation] 向 Angular 4 项目中的滚动阻止“touchstart”事件添加非被动事件侦听器是啥意思?
Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking e
在解决控制台中的 [Violation] 警告时滚动 DIV 时防止页面滚动
非被动事件侦听器导致“阻塞”代码(使用 React Ace)并因此导致性能问题