首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react-simplebar中获取滚动属性(在有状态函数中)

如何在react-simplebar中获取滚动属性(在有状态函数中)
EN

Stack Overflow用户
提问于 2020-02-01 00:36:55
回答 1查看 732关注 0票数 2

我是第一次接触react.js中的引用,在react-simplebar文档中,它只是展示了如何获取无状态函数的滚动引用。

代码语言:javascript
复制
class App extends React.Component {
  render() {
    console.log(this.refs.scroll)    // => Undefined
    return (
      <Simplebar ref={this.refs.scroll}><h1>scrollable element</h1></Simplebar>
    )
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-09 13:44:41

试试这个

代码语言:javascript
复制
class App extends React.Component {
constructor(props) {
        super(props);
        this.scrollableNodeRef = React.createRef();
    }
  
  onChangeScrollToTop() {
        this.scrollableNodeRef.current.scrollTop = 0;

    }
  
  
  render() {
    console.log(this.refs.scroll)    // => Undefined
    return (
      <Simplebar scrollableNodeProps={{ ref:this.scrollableNodeRef }}>
      <h1>scrollableelement</h1>
      </Simplebar>
    )
  }
}

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60007876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档