From 98d74d32f4df73e84f03fdc991b4a3b7392da7e4 Mon Sep 17 00:00:00 2001 From: liuzhihang Date: Fri, 28 Oct 2022 09:23:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=A4=84=E7=90=86=20js=20?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/main.js | 93 +++++++++++++++++++----------------- templates/assets/js/utils.js | 29 +++++------ 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/templates/assets/js/main.js b/templates/assets/js/main.js index 866c9bfe..5bbe257d 100644 --- a/templates/assets/js/main.js +++ b/templates/assets/js/main.js @@ -29,6 +29,53 @@ document.addEventListener("DOMContentLoaded", function () { $nav.classList.add("show"); }; + // 滚动处理 + function scrollFn() { + let a; + let c; + let r; + let s; + let l; + let d; + const $rightside = document.getElementById("rightside"); + const innerHeight = window.innerHeight + 56; + document.body.scrollHeight <= innerHeight + ? ($rightside.style.cssText = "opacity: 1; transform: translateX(-38px)") + : ((c = !(a = 0)), + (r = document.getElementById("page-header")), + document.getElementById("guli_top"), + (s = document.getElementById("cookies-window")), + (l = "function" == typeof chatBtnHide), + (d = "function" == typeof chatBtnShow), + window.addEventListener( + "scroll", + btf.throttle(function (t) { + var e, + n, + o = window.scrollY || document.documentElement.scrollTop, + i = ((n = a < (e = o)), (a = e), n); + 56 < o + ? (i + ? (r.classList.contains("nav-visible") && + r.classList.remove("nav-visible"), + d && !0 === c && (chatBtnHide(), (c = !1))) + : (r.classList.contains("nav-visible") || + r.classList.add("nav-visible"), + l && !1 === c && (chatBtnShow(), (c = !0))), + r.classList.add("nav-fixed"), + s.classList.add("cw-hide"), + "0" === + window.getComputedStyle($rightside).getPropertyValue("opacity") && + ($rightside.style.cssText = + "opacity: 1; transform: translateX(-38px)")) + : (0 === o && r.classList.remove("nav-fixed", "nav-visible"), + ($rightside.style.cssText = "opacity: ''; transform: ''")), + document.body.scrollHeight <= innerHeight && + ($rightside.style.cssText = "opacity: 1; transform: translateX(-38px)"); + }, 200) + )); + } + function scrollFnToDo() { const $cardTocLayout = document.getElementById("card-toc"); const $cardToc = $cardTocLayout.getElementsByClassName("toc-content")[0]; @@ -135,51 +182,7 @@ document.addEventListener("DOMContentLoaded", function () { } - function scrollFn() { - var a, - c, - r, - s, - l, - d, - u = document.getElementById("rightside"), - f = window.innerHeight + 56; - document.body.scrollHeight <= f - ? (u.style.cssText = "opacity: 1; transform: translateX(-38px)") - : ((c = !(a = 0)), - (r = document.getElementById("page-header")), - document.getElementById("guli_top"), - (s = document.getElementById("cookies-window")), - (l = "function" == typeof chatBtnHide), - (d = "function" == typeof chatBtnShow), - window.addEventListener( - "scroll", - btf.throttle(function (t) { - var e, - n, - o = window.scrollY || document.documentElement.scrollTop, - i = ((n = a < (e = o)), (a = e), n); - 56 < o - ? (i - ? (r.classList.contains("nav-visible") && - r.classList.remove("nav-visible"), - d && !0 === c && (chatBtnHide(), (c = !1))) - : (r.classList.contains("nav-visible") || - r.classList.add("nav-visible"), - l && !1 === c && (chatBtnShow(), (c = !0))), - r.classList.add("nav-fixed"), - s.classList.add("cw-hide"), - "0" === - window.getComputedStyle(u).getPropertyValue("opacity") && - (u.style.cssText = - "opacity: 1; transform: translateX(-38px)")) - : (0 === o && r.classList.remove("nav-fixed", "nav-visible"), - (u.style.cssText = "opacity: ''; transform: ''")), - document.body.scrollHeight <= f && - (u.style.cssText = "opacity: 1; transform: translateX(-38px)"); - }, 200) - )); - } + window.refreshFn = function () { initAdjust(); diff --git a/templates/assets/js/utils.js b/templates/assets/js/utils.js index 7046eb00..12478cf2 100644 --- a/templates/assets/js/utils.js +++ b/templates/assets/js/utils.js @@ -73,20 +73,21 @@ const btf = { }) }, - initJustifiedGallery: function (selector) { - selector.forEach(function (i) { - if (!btf.isHidden(i)) { - fjGallery(i, { - itemSelector: '.fj-gallery-item', - rowHeight: 220, - gutter: 4, - onJustify: function () { - this.$container.style.opacity = '1' - } - }) - } - }) - }, + // 图库排版 + // initJustifiedGallery: function (selector) { + // selector.forEach(function (i) { + // if (!btf.isHidden(i)) { + // fjGallery(i, { + // itemSelector: '.fj-gallery-item', + // rowHeight: 220, + // gutter: 4, + // onJustify: function () { + // this.$container.style.opacity = '1' + // } + // }) + // } + // }) + // }, scrollToDest: (pos, time = 500) => { const currentPos = window.pageYOffset