简体   繁体   English

图像-替代加载图像?

[英]IMAGE - Substitute for loading images?

I don't know how it's called so google isn't giving me good answers. 我不知道该怎么称呼,所以google不能给我很好的答案。

How do create a replacement image for an image that is yet to be loaded? 如何为尚未加载的图像创建替换图像?

Like when the image size is big, I'd like to replace it with something like "Loading. Please wait" or something while the image is still being loaded and will be displayed once it has completed loading? 就像图像较大时,我想用“正在加载。请稍候”之类的东西替换它,或者在图像仍在加载时将其替换,并在完成加载后显示?

There is a canonical way to do this: 有一种规范的方法可以做到这一点:

  • Have one single static image of the "loading, please wait" type. 具有“加载中,请稍候”类型的单个静态图像 As it is static, it will be loaded from cache 由于它是静态的,因此将从缓存中加载
  • Load the image you really want to display into an identical image node on a hidden div 将您真正想要显示的图像加载到隐藏div上的相同图像节点中
  • When the image has loaded ( <img onload="..." ...> ) replace the DOM node of the placeholder image with the preloaded node. 加载图像后( <img onload="..." ...> ),将占位符图像的DOM节点替换为预加载的节点。

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

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