From 95e2e85703c43a5b6dde4eee1a570ff12884b97e Mon Sep 17 00:00:00 2001 From: razonyang Date: Fri, 25 Aug 2023 23:06:48 +0800 Subject: [PATCH] fix: adjust the hb-top-offset on initializing and resizing --- assets/hb/modules/header/js/index.ts | 13 +++++++++++++ go.mod | 2 +- go.sum | 12 +++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/assets/hb/modules/header/js/index.ts b/assets/hb/modules/header/js/index.ts index 6611490d..0d437c85 100644 --- a/assets/hb/modules/header/js/index.ts +++ b/assets/hb/modules/header/js/index.ts @@ -1,5 +1,6 @@ import "js/bootstrap/src/dropdown"; import "js/bootstrap/src/offcanvas"; +import params from "@params"; (() => { document.addEventListener('DOMContentLoaded', () => { @@ -27,6 +28,18 @@ import "js/bootstrap/src/offcanvas"; nav.style.zIndex = '0'; } + const topOffset = () => { + const v = nav.clientHeight + parseInt(params.styles.hb_top_offset ?? 24) + document.body.style.setProperty(`--${params.styles.prefix}top-offset`, v + 'px') + } + + if (params.header.sticky) { + topOffset() + window.addEventListener('resize', () => { + topOffset() + }) + } + let h = 0; const threshold = 20; if (document.documentElement.scrollTop !== 0) { diff --git a/go.mod b/go.mod index 64152cdf..dcf1d3f4 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.18 require ( github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 // indirect - github.com/hbstack/hb v0.6.0 // indirect + github.com/hbstack/hb v0.7.0 // indirect github.com/hugomods/icons/vendors/bootstrap v0.5.0 // indirect ) diff --git a/go.sum b/go.sum index 2d52fc45..21a5c916 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,7 @@ github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000 h1:GZxx4Hc+yb0/t3/rau1j8XlAxLE4CyXns2fqQbyqWfs= github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI= -github.com/hbstack/hb v0.3.0 h1:GKsRjWEDh9pIZX4SMkopLC86RTzGQd2FSXXBof91lDQ= -github.com/hbstack/hb v0.3.0/go.mod h1:37E1uTMQx1Hix+VdwlWkW74fi3ct5+KlCCBywv9l3Ac= -github.com/hbstack/hb v0.4.0/go.mod h1:37E1uTMQx1Hix+VdwlWkW74fi3ct5+KlCCBywv9l3Ac= -github.com/hbstack/hb v0.5.0/go.mod h1:37E1uTMQx1Hix+VdwlWkW74fi3ct5+KlCCBywv9l3Ac= -github.com/hbstack/hb v0.5.1/go.mod h1:qlNnPNO1MRsrxxDvFMz98DMFafaBgvtAfBYiteR3i1A= -github.com/hbstack/hb v0.5.2/go.mod h1:S/08mx1tK6yxjQIkSqvpqG8HrBzMBDJq1WC5QjXW9p0= -github.com/hbstack/hb v0.6.0/go.mod h1:S/08mx1tK6yxjQIkSqvpqG8HrBzMBDJq1WC5QjXW9p0= +github.com/hbstack/hb v0.7.0 h1:z+pbW5pdDefLH5kJ13wDXSSjrOhcvNIiCNXv1ui7itc= +github.com/hbstack/hb v0.7.0/go.mod h1:S/08mx1tK6yxjQIkSqvpqG8HrBzMBDJq1WC5QjXW9p0= github.com/hugomods/icons v0.6.0 h1:G6RU93okhPPRDh/jqcew9gwkcYpSpg0rCBv4S6yUAFw= -github.com/hugomods/icons/vendors/bootstrap v0.4.1 h1:E6yhi52RF2M7p7Z3nuubf77YC9PSUbWDAtqNFK4TfXE= -github.com/hugomods/icons/vendors/bootstrap v0.4.1/go.mod h1:3fXUsXdGZa+f31OEKUMDGsrCq1XZwhLvUys8XT63AZM= +github.com/hugomods/icons/vendors/bootstrap v0.5.0 h1:CHEGk677heq2kJZa7XsGHRc3Hwizl9NFkmNw146OVm0= github.com/hugomods/icons/vendors/bootstrap v0.5.0/go.mod h1:kfC17VWV+tNi6PGF4AY7CJBBa1/HEgWxCYq2kNOdcdI=