DEV Community

Discussion on: Build your own virtual scroll - Part II

Collapse
 
trumbitta profile image
William Ghelfi • Edited

Hey, thanks for this post. It's been extremely helpful in the last couple days.

I noticed you specify X items, but can scroll down only to X-1.

E.g. itemCount: 100, displayed items: 0-98

I'm trying to fix it right now, but would appreciate your help :D

Collapse
 
trumbitta profile image
William Ghelfi • Edited

I fixed like this:

// endNode = Math.min(itemCount - 1, endNode + renderAhead);
endNode = Math.min(itemCount, endNode + renderAhead);

But I'm not sure any side-effect would show up or not in a real world scenario.
Thoughts?

Collapse
 
adamklein profile image
adam klein

Thanks!
The calculation for the end node was wrong, because it relied on the start node AFTER I reduced the renderAhead.
Also, visible count should be endNode - startNode + 1 (because if we're displaying nodes 1 to 10, we need 10 nodes, not 9).

Fixed in the example