简体   繁体   English

无法在“IntersectionObserver”上执行“observe”:参数 1 不是“元素”类型

[英]Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'

I have been facing an error in following code star marked option but it was executed the last run of my project but actually today it shows "Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'."我在以下代码星标选项中遇到错误,但它是在我项目的最后一次运行时执行的,但实际上今天它显示“无法在‘IntersectionObserver’上执行‘观察’:参数 1 不是‘元素’类型。” on the browser.在浏览器上。

const counters = document.querySelectorAll(".counter");
  function playCounter() {
    counters.forEach((counter) => {
      counter.innerText = 0;

      let point = +counter.dataset.count;

      let step = point / 100;

      let startCount = function () {
        let displayCount = +counter.innerText;

        if (displayCount < point) {
          counter.innerText = Math.ceil(displayCount + step);
          setTimeout(startCount, 500);
        } else {
          counter.innerText = point;
        }
      };
      startCount();
    });
  }

  let counterSection = document.querySelector(".counter_wrapper");

  let scope = {
    borderMargin: "0px 0px -200px 0px",
  };
  const sectionObserver = new IntersectionObserver(function (entry) {
    if (entry[0].isIntersecting) {
      playCounter();
    }
  }, scope);
  **sectionObserver.observe(counterSection);**

Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element' Maybe you can look at this link. Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not type 'Element'也许你可以看看这个链接。 It helps me solve this problem.它可以帮助我解决这个问题。 In fact, document.queryselector returns null because the element does not exist其实document.queryselector返回null是因为元素不存在

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法在“IntersectionObserver”上执行“观察”:参数 1 不是“元素”类型 - Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element' 无法在“MutationObserver”上执行“观察”:参数 1 不是“节点”类型 - Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' 未捕获的类型错误:无法在“MutationObserver”上执行“观察”:参数 1 的类型不是“节点” - Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node' 无法在“MutationObserver”上执行“观察”:参数 1 不是“节点”类型。 选择2() - Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'. select2() 是什么导致在 IntersectionObserver 上执行观察失败? - What causes this failure to execute observe on IntersectionObserver? 无法在“窗口”上执行“getComputedStyle”:参数 1 的类型不是“元素” - Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' 无法在“元素”上执行“动画”:参数 1 不是“对象”类型 - Failed to execute 'animate' on 'element': parameter 1 is not of type 'object' 一个intersectionObserver观察多个元素或一个intersectionObserver每个元素 - One intersectionObserver to observe many elements or one intersectionObserver per element 我收到“未捕获的类型错误:无法在‘MutationObserver’上执行‘观察’:参数 1 不是‘节点’类型。” - I am getting "Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'." 无法在“节点”上执行“ removeChild”:参数1的类型不是“节点”。 删除元素的方法 - Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'. Ways to remove an element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM