【问题标题】:IntersectionObserver undefined for Internet Explorer未为 Internet Explorer 定义 IntersectionObserver
【发布时间】:2020-05-25 11:25:41
【问题描述】:

我有一个 IntersectionObserver 来延迟加载图像等,其中el 是 HTML 元素,offset 是一个数字。

const observer = new IntersectionObserver((entries) => {
  if (entries[0].isIntersecting === true) {
    el.srcset = this.image;
    observer.unobserve(el);
  }
}, {threshold: [0], rootMargin: this.offset + 'px'});

observer.observe(el);

此观察器在所有浏览器上都可以正常工作,但在 IE11 上却不行。对其进行调试会返回以下错误:

“交叉口观察者”未定义

这使得图像根本无法加载。 IE有解决方案吗?因为我认为 IE 不支持它,但正常行为不应该是最初执行观察者的代码吗?

【问题讨论】:

    标签: javascript html internet-explorer intersection-observer


    【解决方案1】:

    IntersectionObserver 不受 IE 支持。你可以参考this article。如果你想在 IE 中支持它,你可以使用this polyfill。该库在不支持的浏览器中填充原生 IntersectionObserver API。

    【讨论】:

      【解决方案2】:

      InternetExplorer 不支持 IntersectionObserver。 您可以参考以下链接供您参考。 https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Browser_compatibility

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多