From c256f3c30d7b661c29e2cdb3455623f0f33790e7 Mon Sep 17 00:00:00 2001 From: Dimo Dimov Date: Wed, 8 Apr 2020 11:56:52 +0300 Subject: [PATCH] fix: Readjust anchor scroll offset on page load --- _assets/js/api-toc.js | 10 +++++++++- _assets/js/toc.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/_assets/js/api-toc.js b/_assets/js/api-toc.js index 79adcc5..b74a352 100644 --- a/_assets/js/api-toc.js +++ b/_assets/js/api-toc.js @@ -7,7 +7,15 @@ $(function () { e.preventDefault(); animateScrolling(this.hash); }; - + + // Detect hash on page load and readjust scroll offset + var initialHash = window.location.hash; + if (!!initialHash) { + setTimeout(function(){ + animateScrolling(initialHash); + }, 100); + } + $("#markdown-toc") .on("click", "a", function () { $(".section > ul").hide(); diff --git a/_assets/js/toc.js b/_assets/js/toc.js index 987ff84..64deed7 100644 --- a/_assets/js/toc.js +++ b/_assets/js/toc.js @@ -52,7 +52,15 @@ $(function() { e.preventDefault(); animateScrolling(this.hash); }; - + + // Detect hash on page load and readjust scroll offset + var initialHash = window.location.hash; + if (!!initialHash) { + setTimeout(function(){ + animateScrolling(initialHash); + }, 100); + } + // animated scroll // Exclude the app inside the div.theme-preview since it's not in an