簡體   English   中英

未為 Internet Explorer 定義 IntersectionObserver

[英]IntersectionObserver undefined for Internet Explorer

我有一個 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 不支持它,但正常行為不應該是最初執行觀察者的代碼嗎?

IE 不支持IntersectionObserver 你可以參考這篇文章 如果你想在 IE 中支持它,你可以使用這個 polyfill 該庫在不支持的瀏覽器中填充原生IntersectionObserver API。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM