update: 优化背景加载代码

This commit is contained in:
lww155
2026-01-22 16:16:09 +08:00
parent 9d9ca1475d
commit 3e7bc0606a
3 changed files with 29 additions and 17 deletions
@@ -0,0 +1,27 @@
// 背景图加载检测
(function() {
const backgroundContainer = document.getElementById('backgroundContainer');
// 提取背景图片URL
let bgImageUrl = window.getComputedStyle(backgroundContainer).backgroundImage;
const urlMatch = bgImageUrl && bgImageUrl.match(/url\(["']?(.*?)["']?\)/);
if (!urlMatch || !urlMatch[1]) {
console.warn('未提取到有效的背景图片URL');
return;
}
bgImageUrl = urlMatch[1];
const bgImage = new Image();
bgImage.onerror = function() {
console.error('背景图片加载失败:', bgImageUrl);
};
// 加载成功显示模型加载
bgImage.onload = function() {
modelLoading.style.display = 'flex';
};
bgImage.src = bgImageUrl;
})();
@@ -1,15 +0,0 @@
// 背景图加载检测
const backgroundContainer = document.getElementById('backgroundContainer');
// 提取背景图片URL
let bgImageUrl = window.getComputedStyle(backgroundContainer).backgroundImage;
const urlMatch = bgImageUrl.match(/url\(["']?(.*?)["']?\)/);
bgImageUrl = urlMatch[1];
const bgImage = new Image();
bgImage.src = bgImageUrl;
// 加载完成后显示模型加载
bgImage.onload = function () {
const modelLoading = document.getElementById('modelLoading');
if (modelLoading) {
modelLoading.style.display = 'flex';
}
}
+2 -2
View File
@@ -236,8 +236,8 @@
</div>
</div>
<!-- 背景加载检测 -->
<script src="js/ui/bg-image-load-detector.js"></script>
<!-- 背景加载 -->
<script src="js/ui/backgroundLoad.js"></script>
<!-- PIXI.js 2D渲染引擎 -->
<script src="js/live2d/pixi.js"></script>