From 81d8166ff4e4a7b4a74b56ff00a2144fcf9d2cf3 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 24 Jul 2020 23:36:45 +0100 Subject: [PATCH] Animate scrolling when clicking on ToC --- static/src/js/app.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/static/src/js/app.js b/static/src/js/app.js index 0f26c54..4989903 100644 --- a/static/src/js/app.js +++ b/static/src/js/app.js @@ -61,16 +61,26 @@ $(document).ready(function() { }); }); -$('#scroll-top').on('click', function(event) { +function scrollTo(offset) { $('html, body') .stop() .animate( { - scrollTop: 0, + scrollTop: offset, }, 500 ); +} + +$('#scroll-top').on('click', function(event) { event.preventDefault(); + scrollTo(0); +}); + +$('#TableOfContents a').on('click', function(event) { + event.preventDefault(); + const target = $($(this).attr('href')); + scrollTo(target.offset().top); }); $('[data-clipboard-text]').on('click', function(event) {