admin管理员组文章数量:1430702
I have a react ponent with a scrollable div I'm trying to get the div to scroll to the bottom after it mounts:
ponentDidUpdate() {
var scrollNode = ReactDOM.findDOMNode(this.scrollElement);
scrollNode.scrollTop = scrollNode.scrollHeight;
}
the scrollNode exists and reflects the correct div however, the value of scrollTop is never changed (it remains 0 even if i set it to some arbitrary number) and the scroll doesn't occur.
UPDATE: Here's an example:
I have a react ponent with a scrollable div I'm trying to get the div to scroll to the bottom after it mounts:
ponentDidUpdate() {
var scrollNode = ReactDOM.findDOMNode(this.scrollElement);
scrollNode.scrollTop = scrollNode.scrollHeight;
}
the scrollNode exists and reflects the correct div however, the value of scrollTop is never changed (it remains 0 even if i set it to some arbitrary number) and the scroll doesn't occur.
UPDATE: Here's an example: https://codepen.io/johnryan1/pen/BWoeKQ
Share Improve this question edited Mar 1, 2017 at 6:35 john_ryan asked Mar 1, 2017 at 6:04 john_ryanjohn_ryan 1,8272 gold badges21 silver badges35 bronze badges 7- What is it that you want to do? – Deividas Commented Mar 1, 2017 at 6:08
- @DeividasKaržinauskas i'm trying to get the div to scroll to the bottom on mount (i updated the question for clarity) – john_ryan Commented Mar 1, 2017 at 6:09
- Possible duplicate of Scroll to bottom of div? – Deividas Commented Mar 1, 2017 at 6:11
- Try using the solution in the post above. – Deividas Commented Mar 1, 2017 at 6:12
- 1 Can you create a plunker / codepen? – Deividas Commented Mar 1, 2017 at 6:15
1 Answer
Reset to default 4You need to set a height to your container in your css. For example
.list
height: 100px
本文标签: javascriptReact scrollTop not workingStack Overflow
版权声明:本文标题:javascript - React scrollTop not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745563412a2663612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论