From: Svante Bengtson Date: Thu, 17 May 2018 13:02:10 +0000 (+0200) Subject: honour navbar when scrolling to anchor X-Git-Url: https://jfr.im/git/irc/freenode/web-7.0.git/commitdiff_plain/2b4a60ab8266dc1548c4d2928e03584378a2df88?hp=3f51f0f910da2c4fdc7fb7eb08b27e954191af07 honour navbar when scrolling to anchor --- diff --git a/static/js/utils.js b/static/js/utils.js index 52c8eb74f..06a5b872e 100755 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -13,3 +13,11 @@ document.addEventListener('copy', function (event) { event.clipboardData.setData('text/html', newText.replace(/&/g, '&').replace(//g, '>')) event.preventDefault() }) + +/** + * Scroll the page to honour the fixed navbar when linked to an anchor + * @return {Undefined} + */ +function shiftWindow () { if (window.location.hash) window.scrollBy(0, -50) }; +window.addEventListener('hashchange', shiftWindow) +window.onload = shiftWindow