Difference between revisions of "Template:BNU-CHINA/article"

Line 15: Line 15:
 
<script>
 
<script>
 
$(document).ready(function () {
 
$(document).ready(function () {
 
+
     scrollToHash(window.location.hash);
     var baseline = $("#top_menu_14").height();
+
  
 
     $(".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() - baseline}, "slow");
+
             $("html, body").animate({scrollTop: $target.offset().top - $(".sub-header").height()}, "slow");
 
         }
 
         }
     });
+
     }
 
});
 
});
 
</script>
 
</script>

Revision as of 01:12, 19 September 2015