简体   繁体   English

Javascript + HTML:如何有效显示大量图像?

[英]Javascript + HTML: How can I efficiently display a large list of images?

Some context: I'm making a chrome extension that will make use of a large list (potentially thousands) of image urls. 一些背景信息:我正在开发一个chrome扩展程序,它将使用大量(可能是数千个)图像网址。 The list will have urls for many image types. 列表中将包含许多图片类型的网址。

I want to give users the ability to browse these images by seeing the actual image, and not just seeing the url. 我想让用户能够通过查看实际图像而不是仅查看URL来浏览这些图像。 Right now I just iterate through the list, and for each url, I attach an element to a scrollable element. 现在,我只是遍历列表,对于每个URL,我都会将元素附加到可滚动元素。 This results in aa scrollable list of images. 这导致图像的可滚动列表。 Some are gifs, some png, some jpeg etc. I'm worried that if the list gets very large, there will be a lot of lag and the process will take up a lot of bandwidth. 一些是gif,一些png,一些jpeg等。我担心,如果列表很大,将会有很多滞后,并且该过程将占用大量带宽。

Is there a good way to do something like this efficiently (ie. reduce lag and loading times)? 有没有一种有效的方法来有效地执行此类操作(即减少延迟和加载时间)?

Ideally I would have a thumbnail for each url. 理想情况下,我将为每个网址设置一个缩略图。

Obviously the thousands of images are not going to be all displayed at once in a single view but as you described, in a long list. 显然,成千上万的图像不会一次显示在一个视图中,而是像您所描述的那样在长列表中显示。 The approach I would take would be to buffer the images and display them on scroll. 我要采取的方法是缓冲图像并在滚动显示它们。 This would require you to calculate how many images you can store in a row and have at least two or three rows buffered ahead and behind of the current scroll position. 这将需要您计算一行中可以存储多少图像,并且在当前滚动位置的前后至少缓冲两三行。 The only downside to this approach is that it could be tricky to get a smooth scrolling solution it the thumbnail rows are large. 这种方法的唯一缺点是,如果缩略图行很大,要获得平滑的滚动解决方案可能会很棘手。

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

相关问题 如何使用JavaScript在HTML中显示图像数组? - How can I display an array of images in HTML using javascript? Javascript:将鼠标悬停在问题上,如何有效地构造html? - Javascript: Hover over Issues & How can I structure the html efficiently? 如何加快在html / javascript中本地文件系统中大图像的显示 - how to speed up display of large images from local file system in html / javascript 在javascript中,如何在循环中有效地处理大数? - In javascript, how do I deal with large numbers efficiently in a loop? 如何根据javascript中的图像标题显示图像? - How can I display images based on the title of the image in javascript? 如何使用javascript以随机顺序显示文件夹中的图像? - How can I display images from a folder in random order with javascript? 如何有效地实现这些 JavaScript 函数 - How can I implement these JavaScript functions efficiently 如何将大量数字转换为JavaScript数组格式? - How can I convert a large list of numbers into JavaScript array format? 如何使用JavaScript最有效地删除HTML表格行中不同元素中的文本? - How can I strikethrough text in different elements in an HTML table row using JavaScript most efficiently? 如何在单个HTML文件中有效显示10000条记录列表 - How can i present efficiently 10000 record list in single html file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM