最新消息:红方科技年末特惠:.com域名55元、云虚机五折优惠,买3年送2年,更有智能建站套餐等你来取!

JS固定层效果

JS yinhexi 1859浏览 0评论

$(function(){

//nav-autoscroll
var navTop = $('.nav').offset().top;
var navLeft = $('.nav').offset().left;
$(window).bind("scroll",function(){
navAutoScroll(navTop,navLeft);
});

});

function navAutoScroll(navTop,navLeft) {
var scrollTop = document.documentElement.scrollTop;
scrollTop = (scrollTop==0) ? document.body.scrollTop : scrollTop;
if(scrollTop > navTop) {
$('.nav').css({
'top':scrollTop,
'left':navLeft,
'position':'absolute',
'zIndex':'100'
});
} else {
$('.nav').css({
'top':navTop,
'left':navLeft,
'position':'absolute',
'zIndex':'100'
});
}
}

转载请注明:红方博客 » JS固定层效果