Skip to content

Commit 7a55b78

Browse files
committed
loading icon: emoji/URL customization control
Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
1 parent 8a1a0ad commit 7a55b78

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

docs/index.html

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ <h1 style="display:none">KuiklyLoadingView</h1>
281281
</div>
282282
<!-- Overlay -->
283283
<div id="loading-overlay" style="display:none;position:absolute;inset:0;background:rgba(0,0,0,.5);display:none;flex-direction:column;align-items:center;justify-content:center;gap:12px;z-index:10">
284-
<div class="spinner"></div>
284+
<div id="loading-icon-el" class="spinner"></div>
285285
<span id="loading-text" style="color:#fff;font-size:13px">加载中...</span>
286286
</div>
287287
</div>
@@ -694,6 +694,8 @@ <h1 style="display:none">KuiklyLoadingView</h1>
694694
ctrl.innerHTML = ctrlHeader('Loading','全屏/局部加载遮罩') +
695695
ctrlGroup('显示状态', `<label class="ctrl-toggle"><input type="checkbox" id="ld-show" checked onchange="toggleLoading(this.checked)"> 显示遮罩</label>`) +
696696
ctrlGroup('提示文字', `<input type="text" id="ld-txt" value="加载中..." oninput="updateLoadingText(this.value)">`) +
697+
ctrlGroup('图标类型', ctrlBtns('ld-it',['旋转','Emoji','URL'],'旋转','setLoadingIconType')) +
698+
ctrlGroup('图标内容', `<input type="text" id="ld-icon-val" placeholder="emoji 如 🚀 / 图片 URL" style="display:none" oninput="updateLoadingIcon()">`) +
697699
ctrlGroup('遮罩透明度', `<input type="range" min="0.2" max="0.9" step="0.05" value="0.5" id="ld-opacity" oninput="updateLoadingOpacity(this.value)">`) +
698700
`<hr class="ctrl-divider">` + codeBlock(dsl(`Loading {
699701
attr {
@@ -1026,6 +1028,38 @@ <h1 style="display:none">KuiklyLoadingView</h1>
10261028
const o = document.getElementById('loading-overlay');
10271029
o.style.background = `rgba(0,0,0,${v})`;
10281030
}
1031+
let _ldIconType = '旋转';
1032+
function setLoadingIconType(v, el) {
1033+
_ldIconType = v;
1034+
document.querySelectorAll('[onclick^="setLoadingIconType"]').forEach(b => b.classList.remove('active'));
1035+
el.classList.add('active');
1036+
const inp = document.getElementById('ld-icon-val');
1037+
if (inp) {
1038+
inp.style.display = v === '旋转' ? 'none' : '';
1039+
inp.placeholder = v === 'Emoji' ? 'emoji,如 🚀 ⏳ 🔄' : '图片 URL';
1040+
}
1041+
updateLoadingIcon();
1042+
}
1043+
function updateLoadingIcon() {
1044+
const el = document.getElementById('loading-icon-el');
1045+
if (!el) return;
1046+
const val = (document.getElementById('ld-icon-val')?.value || '').trim();
1047+
if (_ldIconType === '旋转') {
1048+
el.className = 'spinner'; el.textContent = ''; el.style.cssText = '';
1049+
} else if (_ldIconType === 'Emoji') {
1050+
el.className = ''; el.textContent = val || '⏳';
1051+
el.style.cssText = 'font-size:42px;line-height:1;filter:drop-shadow(0 2px 4px rgba(0,0,0,.3))';
1052+
} else {
1053+
el.className = ''; el.textContent = '';
1054+
el.style.cssText = 'width:52px;height:52px';
1055+
if (val) {
1056+
const img = document.createElement('img');
1057+
img.src = val; img.style.cssText = 'width:52px;height:52px;object-fit:contain;border-radius:8px';
1058+
img.onerror = () => { img.style.display = 'none'; };
1059+
el.innerHTML = ''; el.appendChild(img);
1060+
}
1061+
}
1062+
}
10291063

10301064
// ─── Toast ────────────────────────────────────────────────────────────────────
10311065
let toastIconSel='无', toastPosSel='中间';

0 commit comments

Comments
 (0)