|
|
|
|
|
by jewel
4362 days ago
|
|
If the page isn't infinitely tall, but instead has a known (but very tall height), having an invisible page element hundreds of thousands of pixels tall makes the scrollbar work perfectly. What content to load is determined based on the scroll position. It also works well to let users jump halfway through a large page, or scroll through a large list faster than the content can be generated. In my implementation, I have some text that pops up (like the alphabet letter that pops up on android when scrolling quickly) with the date so that the user can scroll fast. Note that you also need to remove elements from the DOM that are offscreen (typically above the current position) so that you don't cause the page to be too heavy. I have a photo gallery where the search results can be viewed this way. Even with hundreds of thousands of search results, this approach works very smoothly. I know exactly how many search results the page will have. The images are square and 200px by 200px. I display them tiled. Based on the window size I can calculate how many pixels tall to make the invisible element. The relevant code is https://github.com/jewel/hypercheese/blob/master/app/assets/.... I've been meaning to extract this out and make it a separate library, and also create a demo page. |
|