From 74bdc30f2b3dc1f2010561bd20221800163a5ee7 Mon Sep 17 00:00:00 2001 From: Jesper Kolbeck Date: Fri, 10 Dec 2021 15:28:52 +0100 Subject: [PATCH] Fix button and add hash to URL --- layouts/index.html | 2 +- static/js/index.js | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/layouts/index.html b/layouts/index.html index 632c338..4e6750f 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -14,7 +14,7 @@ {{ with .Params.Name }} {{ $button_title = . }} {{ end }} - {{ $button_title }} + {{ $button_title }} {{ end }} diff --git a/static/js/index.js b/static/js/index.js index 58a41ca..652197f 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -13,12 +13,15 @@ var $sitehead = $("#site-head"); /* Globals jQuery, document */ (function ($) { "use strict"; - function srcTo(el) { + function srcTo(el, dur = 1000) { $("html, body").animate( { scrollTop: el.offset().top, }, - 1000 + dur, + function() { + window.location.hash = el.attr("id"); + } ); } function srcToAnchorWithTitle(str) { @@ -51,19 +54,14 @@ var $sitehead = $("#site-head"); $(".post-title").each(function () { var t = $(this).data("fnav-title"); var index = $(this).parents(".post-holder").index(); + var postId = $(this).closest("article.post").attr('id'); $fnav.append( - "" + t + "" + "" + t + "" ); $(".fn-item").click(function () { - var i = $(this).attr("item_index"); - var s = $(".post[item_index='" + i + "']"); - - $("html, body").animate( - { - scrollTop: s.offset().top, - }, - 400 - ); + var postId = $(this).data("post-id"); + var s = $("#" + postId); + srcTo(s, 400); }); });