I try to fix a separate element on the page when scrolling the page. I use js code:
var position = 0; $(window).scroll(function(e) { var $element = $('.header-st'); var scrollTop = $(this).scrollTop(); if( scrollTop <= 50 ) { $element.removeClass('hide').removeClass('scrolling'); } else if( scrollTop < position ) { $element.removeClass('hide'); } else if( scrollTop > position ) { $element.addClass('scrolling'); if( scrollTop + $(window).height() >= $(document).height() - $element.height() ){ $element.removeClass('hide'); } else if(Math.abs($element.position().top) < $element.height()) { $element.addClass('hide'); } } position = scrollTop; }) On pages where height is great, effect works well - https://monosnap.com/file/652avLqJnn9onOyWcR9iZdT1DJsFEX
But if the height of a small pinned item constantly jumps up - the page becomes unreadable https://monosnap.com/file/E3PIWU5UL1IrMQBdKAilYUOdhHIoQh (the speed is not visible on the screen, but the page is not readable).
How to fix it?