From 02bb0de07d377eb5ef7e9bf16d243c56b02e695b Mon Sep 17 00:00:00 2001 From: John Mulhausen Date: Thu, 2 Mar 2017 04:37:13 -0800 Subject: [PATCH] Anchor links fix --- js/docs.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/js/docs.js b/js/docs.js index 10541e5739..0e7ddcd9d4 100644 --- a/js/docs.js +++ b/js/docs.js @@ -175,6 +175,14 @@ $(document.body).scrollspy({ offset: navHeight }); +function loadHash(hashObj) +{ + // Using jQuery's animate() method to add smooth page scroll + // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area + $('html, body').animate({ + scrollTop: $(hashObj).offset().top-80 + }, 800); +} $(document).ready(function(){ // Add smooth scrolling to all links @@ -188,18 +196,14 @@ $(document).ready(function(){ // Store hash var hash = this.hash; + loadHash(hash); - // Using jQuery's animate() method to add smooth page scroll - // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area - $('html, body').animate({ - scrollTop: $(hash).offset().top-80 - }, 800, function(){ + // Add hash (#) to URL when done scrolling (default click behavior) + window.location.hash = hash; - // Add hash (#) to URL when done scrolling (default click behavior) - window.location.hash = hash; - }); } // End if }); + if (window.location.hash) loadHash(window.location.hash); });