Sticky Nav在较短的页面上发布

问题描述 投票:0回答:1

我使用一些简单的JS创建了一个粘性导航。它似乎适用于大多数页面,但在较短的页面上,它会混淆并开始闪烁,无法下定决心。想知道如何解决这个问题。

这是我的js和ccs

    // Sticky Header
    jQuery(window).scroll(function() {
    console.log(jQuery(window).height());
    console.log(jQuery(document).height());
    if (jQuery(window).scrollTop() > 115 && jQuery(document).height() - (jQuery(window).height() + 345) > 0)
        jQuery('header').addClass('sticky-header');
    else 
        jQuery('header').removeClass('sticky-header');
});

header#header.sticky-header {
position: fixed;
top:0; 
left:0;
width: 100%;
z-index: 9999!important;
-webkit-backface-visibility: hidden !important;

}

这里有几个链接可以看到它的实际效果。

适用于长页面。 https://dev.myavenuea.com/

不适用于较短的页面。 https://dev.myavenuea.com/product-category/apparel/accessories-apparel/

javascript jquery html css
1个回答
0
投票

我想当你用345添加jQuery(窗口).height时,我认为它实际上增加了导致其毛刺的窗口高度。如果您可以克隆该值,然后将它们一起添加到if语句中,那么它不应该是错误的。

© www.soinside.com 2019 - 2024. All rights reserved.