From 91447bbd6f66a1a334b30ea7840e3407bfc7fd33 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 1 Nov 2016 16:00:14 +0800 Subject: webui: Add the main CSS and JavaScript The js code still misses many necessary functions. --- fg21sim/webui/static/js/main.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 fg21sim/webui/static/js/main.js (limited to 'fg21sim/webui/static/js') diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js new file mode 100644 index 0000000..2878721 --- /dev/null +++ b/fg21sim/webui/static/js/main.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2016 Weitian LI + * MIT license + * + * JavaScript codes for the Web UI of "fg21sim" + */ + + +$(document).ready(function () { + /** + * Offset the page to adjust for the fixed navigation banner + */ + var nav_height = $("nav.navigation").outerHeight(); + + var scroll_target = function () { + if ($(":target").length) { + var offset = $(":target").offset(); + var scroll_to = offset.top - nav_height * 1.2; + $("html, body").animate({scrollTop: scroll_to}, 0); + } + }; + + $(window).on("hashchange", scroll_target); + /* FIXME: This seems not work ... */ + if (window.location.hash) { + scroll_target(); + } +}); -- cgit v1.2.2