Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page height change cause sticky element's stuck point shifts #28

Open
themenow opened this issue Apr 20, 2017 · 3 comments
Open

Page height change cause sticky element's stuck point shifts #28

themenow opened this issue Apr 20, 2017 · 3 comments

Comments

@themenow
Copy link

themenow commented Apr 20, 2017

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 themenow changed the title CSS class is-sticky is added from the beginning Page height change cause sticky element's stuck point shifts Apr 21, 2017
@themenow
Copy link
Author

themenow commented Apr 21, 2017

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.

@ladytellur
Copy link

ladytellur commented Apr 21, 2017

@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

@themenow
Copy link
Author

themenow commented Apr 21, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants