[JavaScript] JavaScript检测图片是否已经加载完成 →→→→→进入此内容的聊天室

来自 , 2021-02-24, 写在 JavaScript, 查看 130 次.
URL http://www.code666.cn/view/913eb3f7
  1. function isImageOk(img) {
  2.     // During the onload event, IE correctly identifies any images
  3.     // that weren't downloaded as not complete. Others should too.
  4.     // Gecko-based browsers act like NS4 in that they report this
  5.     // incorrectly: they always return true.
  6.     if (!img.complete) {
  7.         return false;
  8.     }
  9.  
  10.     // However, they do have two very useful properties: naturalWidth
  11.     // and naturalHeight. These give the true size of the image. If
  12.     // it failed to load, either of these should be zero.
  13.     if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
  14.         return false;
  15.     }
  16.  
  17.     // No other way of checking: assume it's ok.
  18.     return true;
  19. }
  20. //javascript/6289

回复 "JavaScript检测图片是否已经加载完成"

这儿你可以回复上面这条便签

captcha