简体   繁体   English

防止浏览器在完全加载之前显示图像的最佳方法是什么?

[英]What's the best way to prevent a browser from displaying images until they are fully loaded?

I would like to set up a lean and mean image gallery, with thumbnails displayed inline. 我想建立一个精简和平均的图片库,缩略图显示为内联。 I'd like them not to windowshade in while loading, I'd like them to simply pop up or, if there's a way to detect their completion, use a jQuery effect like a quick fadeIn(). 我希望他们在加载时不要使用windowshade,我希望它们只是弹出,或者,如果有办法检测它们的完成,请使用jQuery效果,如快速fadeIn()。

I imagine a line of code like: 我想象一行代码如下:

$(".thumb-image").whenLoaded(fadeIn(500)); $( “拇指图像”)whenLoaded(淡入(500))。

But is there such an event? 但是有这样的事件吗? What's it called? 它叫什么?

Use the load event: 使用load事件:

jQuery: jQuery的:

$(window).load(function(){
  // your code for images....
});

Or Vanilla JavaScript: 或香草JavaScript:

window.onload = function(){
  // your code for images....
};

The load event fires after all images, DOM, external resources, frames, etc have loaded. load所有图像,DOM,外部资源,框架等后,将触发load事件。

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

相关问题 一种防止移动浏览器下载和显示图像的方法 - A way to prevent a mobile browser from downloading and displaying images 如何防止在对象完全加载到$ scope中之前加载DOM? - How to prevent DOM from loading until object is fully loaded into $scope? 防止显示未完全加载的图像 - Prevent show not fully loaded images 如果图像尚未完全加载,则插入加载程序图标的最佳方法? - Best way to insert loader icon if images has not been fully loaded? 如何防止部分加载的图像显示? - How to prevent partially loaded images from displaying? 检查动态网页是否已满载的最佳方法是什么? - What is the best way to check if dynamic web pages are fully loaded? 石工隐藏图像,直到完全加载 - Masonry Hide Images until fully loaded 防止带有hidden-md或hidden-lg的图像加载到Bootstrap中的移动设备上的最佳方法是什么? - What's the best way to prevent images with hidden-md or hidden-lg from loading on mobile devices in Bootstrap? 如何让浏览器等待显示页面,直到它完全加载? - How can I make the browser wait to display the page until it's fully loaded? 如何防止在所有脚本完全加载之前单击图像 - how to prevent clicking on an image until all the scripts is fully loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM