IntersectionObserver在Internet Explorer中未定义。

问题描述 投票:0回答:1

我有一个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个回答
0
投票

IntersectionObserver在InternetExplorer中不支持,你可以参考下面的链接,供你参考。https:/developer.mozilla.orgen-USdocsWebAPIIntersection_Observer_API#Browser_compatibility。


0
投票

IntersectionObserver 不被IE支持。您可以参考 本文. 如果你想在IE中支持它,你可以使用 这种填充物. 这个库的多义词填充了本地的 IntersectionObserver API在不支持的浏览器中。

© www.soinside.com 2019 - 2024. All rights reserved.