我有一个画廊导航栏,当页面向下滚动太多时,我希望将其固定在顶部。我的脚本似乎工作正常,但是在应用类时会出现“跳转”(相对于固定位置之间的转换)。
链接(根据您的分辨率,您可能需要最小化页面才能看到效果)。
代码:
<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');
}
});
}