我正在尝试构建某种平滑的滚动-无论如何,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));
}
}
答案 0 :(得分:1)
testList
无法访问该值。使用如下箭头功能:
this