如何在組件中添加onScroll偵聽器來捕獲父元素的滾動?React - 父元素的onScroll偵聽器?
class ChildDiv extends React.Component {
constructor() {
super();
}
handleScrollOfParent() {
// do stuff when parent <main> scrolls;
}
render() {
return (
<div id="child" onScroll={this.handleScrollOfParent.bind(this)}>
// content with overflow: hidden and scroll handled by parent MAIN.
</div>
)
}
}
export default ChildDiv;
渲染父主,這樣<main><ChildDiv /></main>
,我想抓住主要的滾動。
你找到你的解決方案還沒有,我只是下面貼 – thinhvo0108