简体   繁体   English

如何增加 ScrollToBottom 以填充屏幕的高度?

[英]How to grow ScrollToBottom to fill the height of the screen?

Here is a code sandbox that defines a Logs React component and works great. 是一个代码沙箱,它定义了一个Logs React 组件并且效果很好。

It uses react-scroll-to-bottom to show a page with a header and some logs.它使用 react-scroll-to-bottom 来显示带有 header 和一些日志的页面。 Note that because we use a flexbox, the size of log section grows perfectly to fit the height of the screen.请注意,因为我们使用的是 flexbox,所以日志部分的大小可以完美地适应屏幕的高度。

Now I want to place this Logs component inside an App component.现在我想将此Logs组件放在App组件中。 The problem is that now the log section is too tall and another scrollbar appears in addition to the scroll-to-bottom scrollbar.问题是现在日志部分太高了,除了滚动到底部的滚动条之外,还会出现另一个滚动条。 You can see this here .你可以 在这里看到这个。

I think this is because we use 100vh for the height of the Logs component.我认为这是因为我们使用100vh作为Logs组件的高度。 The problem is, if I change this to 100% , ScrollToBottom breaks and displays the full log content as if it were a normal div.问题是,如果我将其更改为100% , ScrollToBottom 会中断并显示完整的日志内容,就好像它是一个普通的 div 一样。 It seems like ScrollToBottom requires a specific type of height such as px , em or vh to work.看起来 ScrollToBottom 需要特定类型的高度,例如pxemvh才能工作。 I'm not sure where to go from here.我不确定 go 从这里到哪里。

How do I grow ScrollToBottom to fill the height of the screen?如何增加 ScrollToBottom 以填充屏幕的高度?

This issue is indeed with using 100vh.这个问题确实与使用 100vh 有关。 You're not accounting for the height of the header.您没有考虑 header 的高度。 You could change the height to something like 90vh and it seems to work.您可以将高度更改为 90vh 之类的东西,它似乎可以工作。 Or even give it a defined height in px.或者甚至给它一个以 px 为单位的定义高度。

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

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