Javascript 谷歌地图 API &非被动事件处理程序 [英] Javascript Google Maps API & non-passive event handlers

查看:40
本文介绍了Javascript 谷歌地图 API &非被动事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近 Chrome 开始发出以下警告:

Recently Chrome started emitting the following warnings:

[违规] 向滚动阻塞的touchmove"事件添加了非被动事件侦听器.考虑将事件处理程序标记为被动"以使页面更具响应性.请参阅 https://www.chromestatus.com/feature/5745543795965952

[Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

这些来自 JavaScript Google Maps API 代码.我可以在自己的代码中将 {passive: true} 添加到 addEventListener() 但不知道如何抑制 Google 库中的警告?

These are coming from the JavaScript Google Maps API code. I'm able to add {passive: true} to addEventListener() in my own code but don't know how to suppress the warning in Googles libraries?

推荐答案

这对我有用.到这里 https://stackoverflow.com/a/55388961/2233069

(function () {
    if (typeof EventTarget !== "undefined") {
        let func = EventTarget.prototype.addEventListener;
        EventTarget.prototype.addEventListener = function (type, fn, capture) {
            this.func = func;
            if(typeof capture !== "boolean"){
                capture = capture || {};
                capture.passive = false;
            }
            this.func(type, fn, capture);
        };
    };
}());

这篇关于Javascript 谷歌地图 API &非被动事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆