【发布时间】:2020-03-15 00:52:21
【问题描述】:
我正在尝试构建某种平滑滚动 - 无论如何this.scroller.scrollRequest 是在我的类中预定义的静态值:
scroller = {
target: null,
ease: 0.05,
endY: 0,
y: 0,
resizeRequest: 1,
scrollRequest: 0,
};
此值在滚动时被更改,似乎滚动时scrollRequest 未定义。怎么样?
无法读取未定义的属性“scrollRequest”
这就是它被调用的地方:
componentDidMount() {
this.fetchProjects();
this.scroller.target = document.querySelector(".ch--scrollable-container");
window.focus();
window.addEventListener("resize", this.onResize());
document.addEventListener("scroll", this.onScroll);
}
onScroll() {
this.scroller.scrollRequest++; <-- causing the error
if (!this.requestId) {
this.requestId = requestAnimationFrame(this.updateScroller.bind(this));
}
}
【问题讨论】:
标签: reactjs typescript