[英]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.