From a264a8c6f7cb8fd2537af227bd0297fcb17d720c Mon Sep 17 00:00:00 2001 From: MHuiG <616001163@qq.com> Date: Mon, 5 Sep 2022 07:43:03 +0800 Subject: [PATCH] =?UTF-8?q?perf(side):=20=E5=A6=82=E6=9E=9C=20sidebar=20?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=EF=BC=8C=E9=9A=90=E8=97=8F=20sidebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/js/app.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/js/app.js b/source/js/app.js index dd530cc58..0a12afd7f 100755 --- a/source/js/app.js +++ b/source/js/app.js @@ -29,10 +29,10 @@ const locationHash = () => { if (target) { setTimeout(() => { if (window.location.hash.startsWith('#fn')) { // hexo-reference https://github.com/volantis-x/hexo-theme-volantis/issues/647 - volantis.scroll.to(target, { addTop: - volantis.dom.header.offsetHeight - 5, behavior: 'instant', observer:true }) + volantis.scroll.to(target, { addTop: - volantis.dom.header.offsetHeight - 5, behavior: 'instant', observer: true }) } else { // 锚点中上半部有大片空白 高度大概是 volantis.dom.header.offsetHeight - volantis.scroll.to(target, { addTop: 5, behavior: 'instant', observer:true }) + volantis.scroll.to(target, { addTop: 5, behavior: 'instant', observer: true }) } }, 1000) } @@ -71,6 +71,15 @@ const VolantisApp = (() => { fn.scrolltoElement(volantis.dom.bodyAnchor); }); + // 如果 sidebar 为空,隐藏 sidebar。 + const sidebar = document.querySelector("#l_side") + if (sidebar) { + const sectionList = sidebar.querySelectorAll("section") + if (!sectionList.length) { + document.querySelector("#l_main").classList.add("no_sidebar") + } + } + // 站点信息 最后活动日期 if (volantis.GLOBAL_CONFIG.sidebar.for_page.includes('webinfo') || volantis.GLOBAL_CONFIG.sidebar.for_post.includes('webinfo')) { const lastupd = volantis.GLOBAL_CONFIG.sidebar.webinfo.lastupd;