0

I'm trying to set up an infinite scrolling on my project, but I have difficulties to make the overflow-y: auto; css property to work. Here's my current layout:

App Layout

And I'm creating it using the following CSS/HTML code:

<div class="flex-items">
      <div v-for="game in gamesData.games" class="card-spacing">
        <!-- Contents -->
      </div>
</div>
.flex-items {
  flex: 1;
  display: flex;
  overflow: auto;
  flex-direction: column;
}
.card-spacing {
  margin-bottom: 10px;
  min-height: min-content; /* needs vendor prefixes */
}

My current troubleshooting steps:

  • I've already tried this StackOverflow Post (Scrolling a flexbox with overflowing content) without any success, the overflow bar doesn't appear at all.
  • If using overflow-y: scroll, only a deactivated scrolling bar seems to appear.
  • The size of the element is bigger than the size of the window, so the elements seems to appear out of the displayed space anyway.

Does anyone have an idea on how to make the scrolling bar appear ?

redblueflame
  • 35
  • 1
  • 11
  • Could you check this codepen https://codepen.io/sulfurious/pen/eWPBjY?editors=1100 – JPA Nov 14 '20 at 11:34

2 Answers2

1

Give the container .flex-items a fixed height or max-height, overflow only works if the content of a container exceeds the height of the container

.flex-items {
  flex: 1;
  display: flex;
  height: 500px // specify a height
  min-height: 100%; // take up the full height of its own container
  overflow: auto;
  flex-direction: column;
}
Redemption Okoro
  • 349
  • 1
  • 11
-1

The parent container needs to have fixed height and the total height of its' child elements need to exceed it. Thus, you would get a scrollbar on the parent.

Then, add scroll event handler to the parent container to check if the user has scrolled to the bottom and fetch more items if so.

const container = document.querySelector('.flex-items');

function loadItems() {
  if (container.scrollTop === container.scrollTopMax) { 
    // fetch more items
  }
}

container.addEventListener('scroll', loadItems);
83C10
  • 1,112
  • 11
  • 19
  • 1
    This issue happened without any JS code, but you helped me with the part about the total size oh the children. See the accepted answer for the correct solution ;) – redblueflame Nov 14 '20 at 12:34
  • I think my first sentence summarizes the accepted answer. Anyways, good luck :) – 83C10 Nov 14 '20 at 20:39