diff --git a/gallery/src/index.js b/gallery/src/index.js index a169768..2c22dcc 100644 --- a/gallery/src/index.js +++ b/gallery/src/index.js @@ -340,6 +340,7 @@ box.appendChild(holder) var tries = 0 function fail (text) { + tries = 999 holder.textContent = text || '缩略图加载失败(点击重试)' holder.style.cursor = 'pointer' holder.onclick = function () { failed[it.name] = 1; tries = 0; boot() } @@ -347,6 +348,7 @@ updateFail() } function boot () { + if (tries >= 999) return holder.style.cursor = '' holder.onclick = null holder.textContent = '加载中…' @@ -397,6 +399,15 @@ }) img.style.display = 'none' box.appendChild(img) + // v1.6.9:坏图/超时兜底 —— 某些坏字节既不触发 load 也不触发 error,700ms 后直接判定失败(可点击重试) + setTimeout(function () { + try { + if (!img.parentNode) return + if (img.naturalWidth > 0) return + if (img.parentNode === box) box.replaceChild(holder, img) + fail('缩略图加载失败(点击重试)') + } catch (e) { /* ignore */ } + }, 700) // 加载成功后再替换占位(避免破图标 + 长 title 占满格子) if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) } else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }