錨點偏移

參照 stackoverflow 的作法,在主體內容前加一個暗錨:javascript

<a class="target-fix" name="a-<?php $a->id(); ?>"></a>
<artivle>主體內容...</article>

將錨點進行偏移,並隱藏佔位:php

.target-fix {
    position: relative;
    top: -44px; // 偏移值
    display: block;
    height: 0;
    overflow: hidden;
}

也能夠這樣,使用javascript去調整scroll值html

if (window.location.hash.indexOf('#') >= 0) {
    $('html,body').animate({
        scrollTop: ($(window.location.hash).offset().top - 50) + "px"
    },
    300);
}; //主要修復評論定位不許確BUG
$('#comments a[href^=#][href!=#]').click(function() {
    var target = document.getElementById(this.hash.slice(1));
    if (!target) return;
    var targetOffset = $(target).offset().top - 50;
    $('html,body').animate({
        scrollTop: targetOffset
    },
    300);
    return false;
}); //主要修復評論定位不許確BUG

padding-top 可能會讓第二條評論向下偏移50px,可是把回覆按鈕給遮擋了!致使回覆按鈕點擊不了。反覆調整z-index改變層的順序,仍然無果!java

相關文章
相關標籤/搜索