如何在反应中滚动到底部? [英] How to scroll to bottom in react?
本文介绍了如何在反应中滚动到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想搭建一个聊天系统,在进入窗口和有新消息进来时自动滚动到底部.在React中如何自动滚动到容器底部?
解决方案
正如 Tushar 提到的,你可以在聊天底部保留一个虚拟 div:
render() {返回 (<div><div className="MessageContainer" ><div className="MessagesList">{this.renderMessages()}
<div style={{ float:"left", clear: "both" }}ref={(el) =>{ this.messagesEnd = el;}}>