fix(gallery): 1.9.4 消除滚动加载时的闪动——卡片按宽高比占位 + 异步解码 + 加大预取
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 34s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 34s
闪动的来源:卡片初始只有「加载中…」那一行字的高度,缩略图一到就从一行字长成整图高, 整列跟着重排,滚动时看起来就是闪一下。 - itemNode:按 it.w/it.h 给卡片设 aspect-ratio,占位阶段就占好最终高度;有宽高时占位文案不写「加载中…」 - styles.css:占位层 absolute inset:0 铺满卡片(否则卡片高了、占位还是 84px 的小框) - img 插入后调用 decode(),解码不占主线程 - 预取范围从 0.8/1.8 屏提到 1.2/2.4 屏,滚动时少触发几次窗口重排
This commit is contained in:
1 parent
b2bcc07cb5
commit
89bb19beab
4 files changed
+16
-10
No files matched your search
@@ -425,8 +425,8 @@
|
||||
if (!force && winState.top >= 0 && grid.firstChild && Math.abs(top - winState.top) < viewH * 0.6 && winState.viewH === viewH) return
|
||||
winState.top = top
|
||||
winState.viewH = viewH
|
||||
var from = Math.max(0, top - viewH * 0.8)
|
||||
var to = top + viewH * 1.8
|
||||
var from = Math.max(0, top - viewH * 1.2)
|
||||
var to = top + viewH * 2.4
|
||||
clear(grid)
|
||||
for (var ci = 0; ci < L.cols.length; ci++) {
|
||||
var colDef = L.cols[ci]
|
||||
@@ -476,7 +476,10 @@
|
||||
origBadge = el('span', { class: 'iwb-gal-origbadge', text: it.orig === 'off' ? '未备份' : '仅缩略图' })
|
||||
origBadge.title = it.orig === 'off' ? '原图入库已关闭:这张只有缩略图' : '原图没有写进本地:右键可「补存原图」'
|
||||
}
|
||||
var holder = el('div', { class: 'iwb-history-missing', text: '加载中…' })
|
||||
// v1.9.4:卡片先按宽高比占位 —— 否则缩略图出现的瞬间卡片从「一行字高」长成整图高,
|
||||
// 整列跟着重排,滚动时就表现为闪动。
|
||||
if (it.w && it.h) { try { box.style.aspectRatio = it.w + ' / ' + it.h } catch (e0) { /* ignore */ } }
|
||||
var holder = el('div', { class: 'iwb-history-missing', text: it.w && it.h ? '' : '加载中…' })
|
||||
box.appendChild(holder)
|
||||
var tries = 0
|
||||
function fail (text) {
|
||||
@@ -516,6 +519,7 @@
|
||||
// 放弃会导致某些卡片永远停在「加载中…」(缩略图缓存已存,只是没人把它挂上去)。
|
||||
var img = el('img', { src: url, alt: '', loading: 'eager', decoding: 'async', draggable: 'true' })
|
||||
if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h)
|
||||
try { if (typeof img.decode === 'function') img.decode().catch(function () {}) } catch (e4) { /* ignore */ }
|
||||
img.addEventListener('load', function () {
|
||||
// naturalWidth=0 说明拿到的是坏图(空 data URL / 截断文件):按失败处理,别留白块
|
||||
if (!img.naturalWidth) { tries++; if (tries <= 2) { setTimeout(boot, 400 * tries); return } if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)'); return }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "gallery",
|
||||
"name": "图库",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
@@ -13,7 +13,7 @@
|
||||
"图库"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "0921ffa067b14de54aeabf5a46cd29a4a2bad2b8d2bd086600324ca7506385d9",
|
||||
"styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde"
|
||||
"main.js": "acfa2c21c22afef3d05f21b38cfc36286f89ac20342b7d985d9da8873e99c18e",
|
||||
"styles.css": "c7db0f9d78b98c1b5bb9782c45dfc2274673c1c7d34fdf676aae41680866eb3d"
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,8 @@
|
||||
border-color: var(--iwb-hover-border, var(--iwb-brand));
|
||||
box-shadow: var(--iwb-hover-shadow, 0 5px 16px rgba(0, 0, 0, .22));
|
||||
}
|
||||
/* v1.9.4:卡片按宽高比占位后,占位层要铺满卡片 —— 否则缩略图出现时仍会有一次高度跳变(滚动时表现为闪动) */
|
||||
.iwb-history-embedded .iwb-history-item .iwb-history-missing { position: absolute; inset: 0; min-height: 0; }
|
||||
.iwb-history-missing {
|
||||
display: flex; align-items: center; justify-content: center; text-align: center;
|
||||
min-height: 84px; padding: 8px; border-radius: 6px; border: 1px dashed var(--iwb-border);
|
||||
|
||||
+4
-4
@@ -33,11 +33,11 @@
|
||||
"dir": "gallery",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"files": {
|
||||
"manifest.json": "62380d625ff676d434d066a6800eccedce224a3a0a4ded83f98459dc60f7c57f",
|
||||
"main.js": "0921ffa067b14de54aeabf5a46cd29a4a2bad2b8d2bd086600324ca7506385d9",
|
||||
"styles.css": "945fd547278cf0388035b22660dfe9401dc0c8d25919fe6204471432e5797cde"
|
||||
"manifest.json": "c083bfd23a1dc2aaa540ad246f3ee3f15e7b00c8d5e7ef7c2ccf4809e6673f2b",
|
||||
"main.js": "acfa2c21c22afef3d05f21b38cfc36286f89ac20342b7d985d9da8873e99c18e",
|
||||
"styles.css": "c7db0f9d78b98c1b5bb9782c45dfc2274673c1c7d34fdf676aae41680866eb3d"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user