我在我的页面上:
<!-- initialization of affix -->
<body data-spy="scroll" data-target="#ds-right-navigation" data-offset="74">
<!-- toggleable content -->
<div class="panel">
<a id="ds-word-link-109401" data-toggle="collapse" data-target="#ds-word-109401" class="h3">1. równy</a>
<section id="ds-word-109401" class="col-md-12 ds-word-box collapse in" style="height: auto;">
...collapseable content
</section>
</div>
<div class="panel">
... next panel
</div>
我遇到的问题如下:
答案 0 :(得分:0)
// scroll to anchor
if(window.location.hash) {
var hash = window.location.hash.replace(/\/$/, "");
if(hash.length){
var top = $(hash).offset().top;
//133 = 74 + 74 - 1, where 74 is offset high and -1px for affix
$('body, html').stop().animate({ scrollTop: $(hash).offset().top -133 }, 500);
}
}
$('a[href^=#]').on('click',function() {
var hash = $(this).attr('href');
if(hash !== '#') {
// top offset is 74 and - 1px is for affix
$('body, html').stop().animate({ scrollTop: $(hash).offset().top -73 }, 500);
}
});