mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update: 优化背景加载代码
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user