From 43e46303a647937beb1143eda1eecb95a1d53f34 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 2 Apr 2025 17:55:53 +0700 Subject: [PATCH] fix: smooth scroll when open help site with hash --- docs/assets/js/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/assets/js/main.js b/docs/assets/js/main.js index d6e266c5b376..af5473602847 100644 --- a/docs/assets/js/main.js +++ b/docs/assets/js/main.js @@ -349,3 +349,25 @@ window.addEventListener('DOMContentLoaded', () => { document.documentElement.style.setProperty('y-axis', `${window.scrollY}px`); }); }); + +if (window.location.hash) { + const lowerCaseHash = window.location.hash.toLowerCase(); + const element = document.getElementById(lowerCaseHash.slice(1)); + + if (element) { + element.scrollIntoView({ + behavior: 'smooth', + }); + } +} + +// Handle hash changes (like back/forward navigation) +window.addEventListener('hashchange', () => { + if (!window.location.hash) { + return; + } + const lowerCaseHash = window.location.hash.toLowerCase(); + document.getElementById(lowerCaseHash.slice(1))?.scrollIntoView({ + behavior: 'smooth', + }); +});