简体   繁体   English

如何滚动已定义最大高度的底部容器?

[英]How to scroll bottom container which has max-height defined?

I have to scroll bottom container which has only max-height defined. 我必须滚动仅定义了max-height的底部容器。 I try use scrollTop = scrollHeight but it does't work for me ? 我尝试使用scrollTop = scrollHeight但对我不起作用?

Please advice 请指教

My container (HTML/JSX): 我的容器(HTML / JSX):

<div>  
  <ListElement />
  <ListElement />
  <ListElement />
  <ListElement />
</div>

CSS 的CSS

display: flex;
max-height: 400px

Expected result 预期结果

Container always scrolled to bottom when the component appear. 出现组件时,容器始终滚动到底部。

Similar solution 类似的解决方案

container.scrollTop = contentHeight - containerHeight;

but above solution working fine only with defined height not max-height ;/ 但以上解决方案只能在定义的高度上不能正常工作max-height; /

尝试container.scrollTo(0, container.scrollHeight)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM