0712-2888027 189-8648-0214
微信公眾號

孝感風信網(wǎng)絡(luò)科技有限公司微信公眾號

當前位置:主頁 > 技術(shù)支持 > Javascript/JQuery > Jquery頭部滾動固定的實現(xiàn)代碼片段

Jquery頭部滾動固定的實現(xiàn)代碼片段

時間:2024-09-20來源:風信官網(wǎng) 點擊: 616次
Jquery頭部滾動固定的實現(xiàn)代碼片段,以下代碼為項目開發(fā)中的片段,實現(xiàn)方法思路僅供參考。

//頭部固定
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();
});
熱門關(guān)鍵詞: Jquery 頭部滾動固定
欄目列表
推薦內(nèi)容
熱點內(nèi)容
展開