Images shake when loading #141
-
I have a website https://vercel.bobjoy.com with PhotoAlbum,I have a confusion. When I open the webpage for the first time, the order of loading images is random. I want to implement sequential loading, so that the user experience may be better, and then when I slide the mouse to the bottom of the page, more data will be loaded. At that time, I added the data to the original data (setPages([...pages, ...data.data]); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
The main issue that I see in your code is that you are not properly sizing your Also, since you are using Next.js, you can also improve the UX by utilizing Next.js I'm pretty sure your concern will be addressed once you implement the above two recommendations. Now, when it comes to the infinite scroll question, the Here are the examples:
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the help you provided, your patience made me feel warm, as well as the code demo, which is very useful for me, I have modified a new version according to the demo you provided and running on https://vercel.bobjoy.com, but there are two new problems. Also, regarding the code snippet in the demo const fetchPhotos = React.useCallback((page: number) => {
let fetchCancelled = false;
fetch(`https://picsum.photos/v2/list?page=${(page % 20) + 1}&limit=50`)
.then((response) => response.json())
.then((data: PicSumPhoto[]) => {
if (!fetchCancelled) {
setPhotos((prev) => [... .prev, shuffle(convert(data))]);
}
});
return () => {
fetchCancelled = true;
}; }
}, []); I would like to know what the fetchCancelled variable does, as well as return () => {
fetchCancelled = true; }; }
}; } What does this return do, forgive my lack of knowledge. Thank you very much. My new source code: https://github.com/onmybob/myblog |
Beta Was this translation helpful? Give feedback.
-
After reading your code, it really dawns on me. A few concise lines of code can solve the problem that I have been confused about for many days. It is really a great help to me. Thank you very much. I think if I keep the bottom image clean, I have to use layout=rows. My code has been updated to display images in this way, https://vercel.bobjoy.com/, but there is an unsolved problem. , although I have tried various methods and consulted the documentation, there is still no solution. That is, after the first page is loaded by default, I try to load the picture of the second page when scrolling to the next page. At this time, I scroll the mouse back. When you get to the first page, you find that the layout of the pictures has changed. For example, at the beginning, there were 3 pictures in the first row and 2 pictures in the second row. When the second page is loaded, the layout may have changed. There are three photos in the second row and other similar problems. How to solve this problem? |
Beta Was this translation helpful? Give feedback.
The main issue that I see in your code is that you are not properly sizing your
<div>
wrappers, which results in layout shift every time an image finishes loading and you end up with dozens of layout shifts before the page finishes loading. I highly recommend you use the following official example as a starting point of your implementation - https://react-photo-album.com/documentation#RenderPhoto_RenderPhotoUsageExampleAlso, since you are using Next.js, you can also improve the UX by utilizing Next.js
next/image
image component (https://react-photo-album.com/examples/nextjs) and implementingplaceholder: "blur"
.I'm pretty sure your concern will be addressed once you implement the above …