这是我的代码
const target = document.querySelector(eventTarget);
const targetPosition = target.getBoundingClientRect();
const startPosition = window.pageYoffset;
const distance = targetPosition - startPosition;
const startTime = null;
function animation(currentTime) {
if(startTime === null )
startTime = currentTime;
const timeElapsed = currentTime - startTime
const run = ease(timeElapsed, startPosition, distance, duration);
}
function ease(t,b,c,d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t-2) - 1) + b;
}
requestAnimationFrame(animation);
}
const clickScroll = () => {
const button = document.getElementById(".button");
button.addEventListener("click", () => {
smoothScroll(".second", 1000);
});
}
export { smoothScroll, clickScroll };
因此,基于控制台,target = document.querySelector(eventTarget);无法工作,因此它为null。 请帮助调试该漏洞并阐明该错误