From 2c226980679e09d713ef7c02605bf60b43aac71d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 2 Oct 2019 14:40:00 +0200 Subject: [PATCH] fixed a long standing bug with blog posts towards the bottom not being scrolled to properly --- scripts/blog.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/blog.js b/scripts/blog.js index 5482363..c4e3f75 100644 --- a/scripts/blog.js +++ b/scripts/blog.js @@ -44,16 +44,17 @@ $.ajax({ if (window.location.hash.startsWith("#blog-")) { var anchor = $(window.location.hash); if (anchor.length) { - openBlogPost(window.location.hash.substring(6)); - $('html, body').animate({ - scrollTop: anchor.offset().top - }, 0) + openBlogPost(window.location.hash.substring(6), function () { + $('html, body').animate({ + scrollTop: anchor.offset().top + }, 0) + }); } } } }); -function openBlogPost(id) { +function openBlogPost(id, onDone) { $.get("blog/" + id + ".md", function (markdown) { let html = converter.makeHtml(markdown); $("#blog-post-" + id).html(html); @@ -61,5 +62,8 @@ function openBlogPost(id) { var discuss = $("#blog-discuss-" + id); if (discuss.length) discuss.html("Discuss this post"); + + if (onDone) + onDone(); }); } \ No newline at end of file