question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set a direct parent div's height, to height of scrollbar?

See original GitHub issue

Hello!

So the issue I face is simple yet a little confusing for me.

I used the basic example in the repo to create a list of 10,000 numbers and assigned parentScroll to the window, which is successfully being virtually scrolled.

Then I have nested the list into a card (having a card in the back of the list is a design necessity):

<mat-card class="custom-card">
    <virtual-scroller #scroll [items]="myItems" [parentScroll]="scroll.window">
      <div *ngFor="let item of scroll.viewPortItems">{{item }}</div>
    </virtual-scroller>
</mat-card>

But even with height: 100% and flex:1, it shows the card like this: image

As highlighted in the console, document.documentElement.scrollHeight only shows 696, which is in reality the clientHeight.

In other words, is there any way to expand this card’s height to fit all the content? Is there any property from ngx-virtual-scroller I could use? And how?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
kmcscommented, Jan 7, 2021

Work around works for me. Idea to get it work not with fixed pixel you have to set a height on each parent: https://stackoverflow.com/questions/31728022/why-is-percentage-height-not-working-on-my-div/31728799#31728799 But it’s even harder as your workaround… it would be nice if the virtual-scroll-element has a property so own calculation is not needed.

0reactions
SaadBazazcommented, Jan 19, 2021

Is this a solution to our problem? -> https://github.com/rintoj/ngx-virtual-scroller/pull/447

I’d like to know if anyone has tried this out to solve our particular issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Define scroll div height by parent. Any tips? - Stack Overflow
and I need to place a #footer element below and let the top remaing space to a scrollable div, but is not possible...
Read more >
height - CSS: Cascading Style Sheets - MDN Web Docs
The height CSS property specifies the height of an element. By default, the property defines the height of the content area.
Read more >
Nesting and overflow - Mockupless
In HTML, create a flex parent container. Make it full-screen using height: 100vh . Paste the result of the task in the flex:...
Read more >
CSS Height Full Page: CSS gotcha: How to fill page with a div?
A very common practice is to apply height: 100vh and width: 100vw to <body> directly... ... In this case, we can even keep...
Read more >
Element size and scrolling - The Modern JavaScript Tutorial
Setting scrollTop to 0 or a big value, such as 1e9 will make the element scroll to the very top/bottom respectively. Don't take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found