繁体   English   中英

如何检测浏览器是否正在加载

[英]How to detect if the browser is loading

当用户单击将在同一页面中显示大图像的链接时,我试图显示加载图像。

我想知道在已经加载页面时检测图像加载的最佳方法是什么(因此window.onload()不起作用)。

$("img.loader").show();
$("img.big").ready(function() {
  $("img.loader").hide();
}):

使用JavaScript加载图像,然后您可以使用图像的onLoad属性:

Image1 = new Image();
Image1.src = 'photo.gif';

/* Code here to display loading hour glass etc */

Image1.onload = function() {
                           /* Image has loaded here */
                        }

将“onclick”事件添加到您的链接,其中通过setTimeout显示您的加载图像。 例如

<a href="...some slow loading page" onclick="setTimeout(showLoading,1)">Link Text</a>

function showLoading() {
   // Code to show "Loading..."
}

暂无
暂无

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

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