ページが下にスクロールしすぎたときに上部に固定したいギャラリー ナビゲーション バーがあります。私が持っているスクリプトは正常に動作しているようですが、クラスが適用されると「ジャンプ」があります(固定位置に対する相対的な移行)。
リンク(解像度によっては、効果を確認するためにページを最小化する必要がある場合があります)。
コード:
<style>
.HighIndex {z-index: 40; position: fixed; top: 10px;}
</style>
スクリプト:
var msie6 = $.browser == 'msie' && $.browser.version < 7;
if (!msie6) {
var top = $('#navContainer').offset().top - parseFloat($('#navContainer').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#navContainer').addClass('HighIndex');
} else {
// otherwise remove it
$('#navContainer').removeClass('HighIndex');
}
});
}