From 761870b3da640dd727733d2a76fb9d7c88e8b7dc Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 16 Nov 2016 13:16:08 +0800 Subject: webui: Rename "scroll_target()" to "scrollTarget()" and export it --- fg21sim/webui/static/js/main.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'fg21sim/webui/static') diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js index 99f9c10..3e10fa3 100644 --- a/fg21sim/webui/static/js/main.js +++ b/fg21sim/webui/static/js/main.js @@ -8,23 +8,22 @@ "use strict"; -$(document).ready(function () { - /** - * Offset the page to adjust for the fixed navigation banner - */ - var nav_height = $("nav.navigation").outerHeight(); +/** + * Scroll the page to adjust for the fixed navigation banner + */ +var scrollTarget = function (height) { + if ($(":target").length) { + var offset = $(":target").offset(); + var scroll_to = offset.top - height * 1.2; + $("html, body").animate({scrollTop: scroll_to}, 100); + } +}; - 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(); - } +$(document).ready(function () { + // Scroll the page to adjust for the fixed navigation banner + $(window).on("hashchange", function () { + var nav_height = $("nav.navigation").outerHeight(); + scrollTarget(nav_height); + }); }); -- cgit v1.2.2