jquery导航条悬浮停止(浏览器窗口)页面顶部 兼容ie6

作者:袖梨 2022-11-14

css代码

代码如下 复制代码

.nav_scroll{ position:fixed;top:0;left:0;z-index:1200; width:100%;}


js代码

代码如下 复制代码

if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
var handler,sTop,dTop;
dTop = $("#fixedNav").offset().top
$(window).bind('scroll',function(){
window.clearTimeout(handler);
handler = window.setTimeout(function(){
sTop = $(document).scrollTop();
sTop > dTop ? $("#fixedNav").css("top",sTop - dTop) : $("#fixedNav").css("top",0);
$("#fixedNav").css({"position":"relative","z-index":"1200"});
},60);
});
}else{

var topMain= $("#fixedNav").offset().top
$(window).scroll(function(){
if ($(window).scrollTop()>topMain){
$("#fixedNav").addClass("nav_scroll");
}else{
$("#fixedNav").removeClass("nav_scroll");
}
});

}
});

html

代码如下 复制代码

id=fixedNav>

相关文章

精彩推荐