简体   繁体   English

防止滚动跳上

[英]Prevent scroll from jumping up

I have implemented endless scrolling for showing posts. 我已经实现了无休止的滚动显示帖子。 After I stop scrolling after say 100 items, item number 98 is visible in viewport. 我说100个项目后停止滚动后,在视口中将看到项目编号98。 But, after images from upper items are loaded they push all subsequent posts down. 但是,在加载上层项目的图像后,它们会将所有后续帖子下推。 Because scrollTop is preserved and 98 item's offsetTop is bigger than when I stoped scrolling, it looks like whole content is scrolled up. 因为保留了scrollTop且98项的offsetTop比我停止滚动时大,所以看起来整个内容都在向上滚动。

Basically, I would like to freeze scroll so that displayed items stay same as when I stopped scrolling. 基本上,我想冻结滚动,以便显示的项目与我停止滚动时保持不变。 Of course, user should be able to continue scrolling. 当然,用户应该能够继续滚动。

Would it be possible to assign a width and height to your images? 可以为图像分配widthheight吗? In this case, the browser displays a placeholder for the image and the content doesn't jump around. 在这种情况下,浏览器将为图像显示一个占位符,并且内容不会跳来跳去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM