From 5c3e0aa46535ed5de08147d6122f547698b8b767 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Tue, 20 Jan 2026 23:22:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=87=92=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=9C=AA=E5=90=AF=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 argonConfig.lazyload 配置逻辑,默认启用懒加载 - 修复懒加载初始化时机,确保 DOM 加载完成后再执行 - 添加 DOMContentLoaded 事件监听,避免过早初始化导致找不到图片元素 - 修复懒加载禁用判断,同时支持 false 和 'false' 字符串 - 优化 header.php 中的懒加载配置,使用 get_option 默认值 --- argontheme.js | 15 ++++++++++++--- header.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/argontheme.js b/argontheme.js index 513ba57..1a5684c 100644 --- a/argontheme.js +++ b/argontheme.js @@ -2312,7 +2312,7 @@ function lazyloadInit() { } // 检查是否启用懒加载 - if (argonConfig.lazyload === false) { + if (argonConfig.lazyload === false || argonConfig.lazyload === 'false') { // 未启用懒加载时,直接加载所有图片 let images = document.querySelectorAll('img.lazyload[data-src]'); images.forEach(function(img) { @@ -2328,7 +2328,9 @@ function lazyloadInit() { } let images = document.querySelectorAll('img.lazyload[data-src]'); - if (images.length === 0) return; + if (images.length === 0) { + return; + } let effect = argonConfig.lazyload_effect || 'fadeIn'; let threshold = parseInt(argonConfig.lazyload_threshold) || 800; @@ -2413,7 +2415,14 @@ function loadImage(img, effect) { }; tempImg.src = src; } -lazyloadInit(); + +// 确保 DOM 加载完成后再初始化懒加载 +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', lazyloadInit); +} else { + // DOM 已经加载完成,立即初始化 + lazyloadInit(); +} /*Pangu.js*/ function panguInit(){ diff --git a/header.php b/header.php index 683bf03..fc73caa 100644 --- a/header.php +++ b/header.php @@ -459,7 +459,7 @@ pangu: "", // 懒加载配置 - lazyload: , + lazyload: , lazyload_effect: "", lazyload_threshold: ,