スムーズなスクロールがデスクトップ用に完全にうまく動作する固定トップナビゲーションバー(75px高さ)があります。私が小さな画面にいるときは、アンカードーズが正しい場所に届くように、高さの低い別のnavbar(高さ50px)を持っています。異なる高さを持つ複数の固定されたnavbarのスムーススクロール
// Smooth Scoll
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//,'')
&&
location.hostname == this.hostname
) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top -75
}, 1200, function() {
var $target = $(target);
$target.focus();
if ($target.is(":focus")) {
return false;
} else {
$target.attr('tabindex','-1');
$target.focus();
};
});
}
}
});
target.offset().top
は、クリックしたナビゲーションバーに応じて設定できます。いいえ、CSSのソリューションをお願いします。
上のNAVの高さは、単にの高さ75を交換取得する可能性がありますナビバー。または、画面に75または50を追加する条件を追加します。 –