Sticky navigation element jumps during scroll

后端 未结 4 1021

In Firefox especially, I\'ve run into an issue I can\'t figure out how to fix.

On the following page, when scrolling down the page jumps several times - mainly on s

4条回答
  •  梦毁少年i
    2020-12-23 19:56

    I solved the problem differently so on firefox as you can see in logs it scroll up itself so to stop this scrolling I made simple statement

    $(document).ready(function () {
            var header = $('#left-menu');
            var offset = header.offset().top;
            var up = true;
            $(window).scroll(function () {
                var scroll = $(window).scrollTop();
                console.log(scroll + ' ' + offset )
                if (scroll >= offset) {
                    header.addClass('sidebar-sticky');
                    if (up){
                        $(window).scrollTop(offset);
                        up=false;
    
                    }
    
    
                } else {
                    up=true;
                    header.removeClass('sidebar-sticky');
                }
            });
    
    
        });
    

    that solution work for me when I can't specify height of div's I use.

提交回复
热议问题