sticky-state icon indicating copy to clipboard operation
sticky-state copied to clipboard

Page height change cause sticky element's stuck point shifts

Open themenow opened this issue 8 years ago • 3 comments

Tested in Chrome, Firefox and IE, when a page has content added dynamically on scrolling, the sticky element changes its stuck point, that to say if the element is supposed to stuck when it reaches top, it won't happen until you keep scrolling down at a certain distance which the distance is height of the dynamically added content.

Please fix this issue, thanks!

themenow avatar Apr 20 '17 15:04 themenow

About title change:

It seems it's the expected behavior for an element stay on top at the beginning, so the real issue is the sticky element changes the point of when to stuck.

themenow avatar Apr 21 '17 04:04 themenow

@kamiyeye you could try to force state change after page content(height) has been changed.

Something like myStickyHeader = StickyState.apply(stickyElement); ...

function forceStateUpdate) {
  for (var i = 0, l = myStickyHeader.items.length; i < l; i++) {
    var values = myStickyHeader.items[i].getStickyState();
    values = $.extend({}, values, myStickyHeader.items[i].getBounds());
    myStickyHeader.items[i].setState(values);
  }}

that's might be because of getBounds wasn't called on content height change

ladytellur avatar Apr 21 '17 05:04 ladytellur

I have changed my JS code back to before

    $(window).scroll(function() {
        var y = $(this).scrollTop();
        if (y > 0) {
            header.addClass('fixed');
        } else {
            header.removeClass('fixed');
        }
    });

but added a line in CSS for fixed header

.fixed {
  position:fixed;
  position:sticky;
}

this works in all major browsers and page height doesn't matter. I think Stickystate is decent for elements sit in somewhere middle of a page, but not the best for sticky header.

themenow avatar Apr 21 '17 09:04 themenow