我有一个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上不支持,但正常的行为不应该是最初执行观察者的代码吗?
IntersectionObserver在InternetExplorer中不支持,你可以参考下面的链接,供你参考。https:/developer.mozilla.orgen-USdocsWebAPIIntersection_Observer_API#Browser_compatibility。