fix: preload bg image before crossfade to eliminate black flash
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e0a518fa13
commit
af0c2d6eb2
1 file changed
+7
@@ -62,6 +62,7 @@ let _npBgLastUrl = '';
|
|||||||
function _crossfadeNpBg(cv) {
|
function _crossfadeNpBg(cv) {
|
||||||
if ((cv || '') === _npBgLastUrl) return;
|
if ((cv || '') === _npBgLastUrl) return;
|
||||||
_npBgLastUrl = cv || '';
|
_npBgLastUrl = cv || '';
|
||||||
|
const doFade = () => {
|
||||||
const currEl = document.getElementById(`np-bg-${_npBgCurr}`);
|
const currEl = document.getElementById(`np-bg-${_npBgCurr}`);
|
||||||
const nextId = _npBgCurr === 'a' ? 'b' : 'a';
|
const nextId = _npBgCurr === 'a' ? 'b' : 'a';
|
||||||
const nextEl = document.getElementById(`np-bg-${nextId}`);
|
const nextEl = document.getElementById(`np-bg-${nextId}`);
|
||||||
@@ -70,6 +71,12 @@ function _crossfadeNpBg(cv) {
|
|||||||
nextEl.style.opacity = '1';
|
nextEl.style.opacity = '1';
|
||||||
currEl.style.opacity = '0';
|
currEl.style.opacity = '0';
|
||||||
_npBgCurr = nextId;
|
_npBgCurr = nextId;
|
||||||
|
};
|
||||||
|
if (!cv) { doFade(); return; }
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = doFade;
|
||||||
|
img.onerror = doFade;
|
||||||
|
img.src = cv;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _syncNpDirect(s) {
|
export function _syncNpDirect(s) {
|
||||||
|
|||||||
Reference in new issue
Block a user