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

v3.3.4: Affix plugin has problems handling items with offsetTop = 0 #16449

Closed
rafalp opened this issue May 8, 2015 · 2 comments
Closed

v3.3.4: Affix plugin has problems handling items with offsetTop = 0 #16449

rafalp opened this issue May 8, 2015 · 2 comments
Labels

Comments

@rafalp
Copy link

rafalp commented May 8, 2015

Background

I have custom navbar in my app. Depending on configuration this navbar is either located at top of page, or its below user set header.

Issue

If there's element taking height above affixed one, everything works, however if affix element is at top of page, click events will switch it between affix/affix-top.

This is because if affix isn't affixed and its offsetTop is 0, following line in getState will change it to 'top':

if (offsetTop != null && scrollTop <= offsetTop) return 'top'

Next click event will trigger getState again, this time changing state back off:

if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false

Temporary fix

I have managed to fix this issue, by changing offsetTop to 1 if navbar has no element obove it (and making existing logic work).

Proposed fix

because offsetTop == 0 is edge case, getState may check for it via running following check before all other checks:

if (offsetTop === 0) return scrollTop === 0 ? 'top' : false
@rafalp rafalp changed the title Affix plugin has problems handling items with offsetTop = 0 v3.3.4: Affix plugin has problems handling items with offsetTop = 0 May 8, 2015
@cvrebert cvrebert added the js label May 8, 2015
kkirsche added a commit to kkirsche/bootstrap that referenced this issue May 14, 2015
[Closes twbs#16449] Affix plugin w/ items with offsetTop = 0

Not sure how to test this change specifically so if anyone has any suggestions on testing this let me know and I'll add it. I wasn't sure if offsetTop = 0; could be achieved via margin-top: 0; padding-top: 0; or if it had to be done differently
@davidgraca
Copy link

Thanks for the fix it really helped! 👍

@cvrebert cvrebert added the v3 label Aug 19, 2015
@mdo
Copy link
Member

mdo commented Sep 5, 2016

Bootstrap 3 is no longer being officially developed or supported.

All work has moved onto our next major release, v4. As such, this issue or pull request is being closed as a "won't fix." For additional help and support, we recommend utilizing our community resources. Thanks for your understanding, and see you on the other side of v4!

<3,
@mdo and team

@mdo mdo closed this as completed Sep 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants