javascript - 如何在 antd 步骤中滚动到顶部。反应
问题描述
我正在使用antd
. 我希望每当用户进入下一步或上一步时,页面应该滚动到顶部。我使用 window.scrollTo(0, 0) 和 window.top=0; 但它不起作用。谁能帮助我如何滚动到顶部。
previousStep = () => {
window.scrollTo(0, 0);
window.scrollTop = 0;
const { currentStep } = this.state;
this.setState({ currentStep: currentStep - 1 });
};
解决方案
onstructor(props) {
super(props)
this.myRef = React.createRef() // Create a ref object
}
componentDidMount() {
this.myRef.current.scrollTo(0, 0);
}
render() {
return <div ref={this.myRef}></div>
} // attach the ref property to a dom element
推荐阅读
- c# - 无法识别的元素“删除”web.config
- java - 使用 JAVA 下载 CSV 文件
- javascript - 使用 chartjs 为特定数据集创建填充线性图表
- javascript - 在此查询中,我需要添加什么使其永远不会显示空白或空值?
- python - Python 3 Regex TypeError:预期的字符串或类似字节的对象
- angular - 输入字段中的图标重叠
- dependency-injection - 统一注册具有多个生命周期的服务
- javascript - 如何使用 qliksense 在 javascript 中使用“require”?
- python - 除了不好的命名约定之外,使用数据类型名称(例如:datetime、str、int)之类的变量名称有什么害处?
- c# - 为什么新的 CosmosDB V3 SDK 中不包含资源类,而旧的 CosmosDB SDK 中存在资源类?