Difference between revisions of "Template:BNU-CHINA/article"
(8 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
<script> | <script> | ||
$(document).ready(function () { | $(document).ready(function () { | ||
− | |||
var baseline = $("#top_menu_14").height(); | var baseline = $("#top_menu_14").height(); | ||
+ | var scrollToHash = function(hash) { | ||
+ | if (hash.indexOf("#") == 0) { | ||
+ | var $target = $(hash); | ||
+ | $("html, body").animate({scrollTop: $target.offset().top - $(".sub-header").height() - baseline + 2}, "slow"); | ||
+ | } | ||
+ | }; | ||
+ | |||
$(".sub-header").css({ | $(".sub-header").css({ | ||
Line 75: | Line 81: | ||
} | } | ||
}); | }); | ||
− | $("a[href | + | |
+ | $("a[href]").on("click", function() { | ||
var hash = this.href.substring(this.href.indexOf("#")); | var hash = this.href.substring(this.href.indexOf("#")); | ||
− | + | scrollToHash(hash); | |
− | + | ||
− | + | ||
− | + | ||
}); | }); | ||
+ | |||
+ | scrollToHash(window.location.hash); | ||
+ | |||
}); | }); | ||
</script> | </script> |
Latest revision as of 01:33, 19 September 2015