diff options
| author | Aaron LI <aaronly.me@outlook.com> | 2016-11-16 13:16:08 +0800 | 
|---|---|---|
| committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-16 13:16:08 +0800 | 
| commit | 761870b3da640dd727733d2a76fb9d7c88e8b7dc (patch) | |
| tree | de977231afd85a09f6fa92140ba0c40fca4c9685 /fg21sim/webui/static/js | |
| parent | 426e90d6578fd84c65c5c864117f5cc36321447f (diff) | |
| download | fg21sim-761870b3da640dd727733d2a76fb9d7c88e8b7dc.tar.bz2 | |
webui: Rename "scroll_target()" to "scrollTarget()" and export it
Diffstat (limited to 'fg21sim/webui/static/js')
| -rw-r--r-- | fg21sim/webui/static/js/main.js | 33 | 
1 files changed, 16 insertions, 17 deletions
| 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); +  });  }); | 
