gpt4 book ai didi

javascript - 动态加载图像

转载 作者:行者123 更新时间:2023-11-29 09:53:44 25 4
gpt4 key购买 nike

我必须在单个页面中显示大量不同大小的 Image

<div id="box1">
<span>Something About Image Goes Here</span>
<img src="img1.jpg" id="img1" />
</div>
<div id="box2">
<span>Something About Image Goes Here</span>
<img src="img2.jpg" id="img2" />
</div>
---
---
<div id="box30">
<span>Something About Image Goes Here</span>
<img src="img30.jpg" id="img30" />
</div>

如果我使用这样的代码,我的页面将需要很长时间才能完全加载,所以我希望所有图像不应该一次加载只有视口(viewport)内的图像(网页的可见部分)应该被加载first 和 rest 应该在用户滚动到它们时加载。

注意
我不希望它用于 text(我在代码中使用的图像信息),文本应该立即正常显示。
就像在 facebook 中一样,当用户向下滚动时它会加载新内容,但在这里我只想要图像,我使用的是装饰过的 div 并且当用户向下滚动时相应的图像必须出现在该 div 中。 (我还想添加一个加载图像,直到图片完全加载)

最佳答案

您可以使用 jQuery lazyload plugin为此。

Lazy Load is a jQuery plugin written in JavaScript. It delays loading of images in long web pages. Images outside of viewport (visible part of web page) wont be loaded before user scrolls to them.

关于javascript - 动态加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com