Jquery顶部滚动固定的代码片段

Jquery顶部滚动固定的代码片段

 

以下代码为项目开发片段,实现方法仅供参考。

 

//头部固定

 

var animateFlag = 1;

 

$(document).scroll(function () {

 

var scrollTop = $(document).scrollTop();

 

if (scrollTop > 65) {

 

$(“#header”).addClass(‘header-fixed’);

 

if (animateFlag) {

 

animateFlag = 0;

 

$(“#header”).stop().animate({

 

‘top’: ‘0px’

 

}, 500);

 

}

 

} else {

 

if (animateFlag == 0) {

 

animateFlag = 1;

 

$(“#header”).removeClass(‘header-fixed’);

 

$(“#header”).animate({

 

‘top’: ‘-65px’

 

}, 500);

 

}

 

}

 

});

 

 

 

 

// 头部导航悬浮

 

function fixed() {

 

var scrollTop = $(document).scrollTop();

 

if (scrollTop > 140) {

 

$(“#new-header”).addClass(“header-fixed”);

 

$(‘#body-container’).css(‘padding-top’, ’60px’);

 

}

 

else {

 

$(“#new-header”).removeClass(“header-fixed”);

 

$(‘#body-container’).css(‘padding-top’, ‘0’);

 

}

 

}

 

 

 

 

fixed();

 

$(window).scroll(function () {

 

fixed();

 

});

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容