reactjs - 在 ReactJs 组件中滚动到顶部
问题描述
我有很多搜索过滤器和一个分页组件。当用户单击分页组件而不是搜索过滤器组件时,我想滚动到顶部。现在,即使用户点击搜索组件,页面也会跳到顶部。非分页点击时如何防止页面滚动到顶部?我正在使用一个类组件。
...
constructor(props) {
super(props)
this.myRef = React.createRef()
}
scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)
render() {
return <div>
<div id="search"><Search1 .../><Search2 .../></div>
<div ref={this.myRef}><Pagination /></div>
</div>
}
解决方案
推荐阅读
- javascript - 将图片的长度分配给按钮的长度
- x86 - 在将 XGETBV 的结果用于 XSETBV 之前,我应该还是不应该掩盖它们?
- cypress - 赛普拉斯:新的 cy.intercept() 方法是否应该模拟不是从浏览器发送的请求的响应,而是使用 cy.request() 方法?
- reactjs - 如果在输入字段中未进行任何更改,如何禁用提交按钮?
- swift - AFHTTPRequestOperation 的合适替代品是什么?
- jwt - springdoc:如何为请求设置默认的 JWT 令牌(演示 API)?
- powershell - PowerShell 远程处理未安装 MSI
- javascript - 如何使用material-ui动态添加/删除类名?
- swift - 是否有类似于 Java 中的 Reentrant Lock for Swift 的库?
- python - 这个生成器 for 循环的扩展形式是什么?