DEV Community

Discussion on: Build your own virtual scroll - Part II

Collapse
 
slidenerd profile image
slidenerd

how would you handle window resize in this? all the heights become stale as the window is resized, only a few items are on the DOM and only their modified heights can be obtained, you have to shift everything up or down

Collapse
 
adamklein profile image
adam klein

I guess if the container's dimensions change (for any reason) we need to recalculate from scratch.
But 'scrollTop' should remain the same, so probably no need to shift anything, just display more or less nodes depending on the new height.

Collapse
 
slidenerd profile image
slidenerd

i am talking about width change on resize, the displacement of each row from the top would totally get disturbed if the width were to change on resize, how do you think that should be handled? :) thank you for the response

Thread Thread
 
adamklein profile image
adam klein

Why should the width affect the calculations? I'm not following

Thread Thread
 
slidenerd profile image
slidenerd

you record heights of 50 rows, you change the width to compress the rows, depending on contents, some of the rows increase in their height, your stored heights are now invalid

Thread Thread
 
adamklein profile image
adam klein

I think this kind of situation is problematic for a virtual scroll of this sort, since the heights are returned per row, and usually not calculated based on measuring DOM nodes' dimensions.
So I would limit the "shrink factor" of the tree view and prevent the rows from wrapping and increasing in height.