2017-10-03 19 views
1

スクロール・ブロッキング「touchstart」イベントに非受動的なイベントリスナーを追加しましたchrome.Iでアプリケーションを開くと、この警告警告:

を取り除く方法がわからないながら、私は奇妙な警告を取得しています

[違反]スクロールブロッキング 'マウスホイール'イベントに非受動的なイベントリスナーを追加しました。 にイベントハンドラを 'パッシブ'とマークして、ページのレスポンスを向上させることを検討してください。

いずれかplsはイベントリスナーのAPIのアップデートがあり、私は事前にthis.Thanksに

答えて

3

を置くのに役立ちます。

document.addEventListener('touchstart', handler, true); 

はこのようになります:この要するに

document.addEventListener('touchstart', handler, {capture: true}); 

あなたのケースでは、あなたはそれがそのようにする必要がありtouchstartするイベントリスナーを添付しているので:

document.addEventListener('touchstart', handler, {passive: true}); 

この方法正確なイベントを事前に設定し、パッシブインターフェイスがサポートされているかどうかを設定することができます:

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); 

詳細: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md