Difference between revisions of "Template:BNU-CHINA/article"
Line 15: | Line 15: | ||
<script> | <script> | ||
$(document).ready(function () { | $(document).ready(function () { | ||
− | + | scrollToHash(window.location.hash); | |
− | + | ||
$(".sub-header").css({ | $(".sub-header").css({ | ||
Line 75: | Line 74: | ||
} | } | ||
}); | }); | ||
+ | |||
$("a[href^=#]").on("click", function() { | $("a[href^=#]").on("click", function() { | ||
var hash = this.href.substring(this.href.indexOf("#")); | var hash = this.href.substring(this.href.indexOf("#")); | ||
+ | scrollToHash(hash); | ||
+ | }); | ||
+ | |||
+ | var scrollToHash = function(hash) { | ||
if (hash.indexOf("#") == 0) { | if (hash.indexOf("#") == 0) { | ||
var $target = $(hash); | var $target = $(hash); | ||
− | $("html, body").animate({scrollTop: $target.offset().top - $(".sub-header").height() | + | $("html, body").animate({scrollTop: $target.offset().top - $(".sub-header").height()}, "slow"); |
} | } | ||
− | } | + | } |
}); | }); | ||
</script> | </script> |
Revision as of 01:12, 19 September 2015