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

Fixes sticky element glitch #2303

Merged
merged 1 commit into from
Nov 26, 2021
Merged

Fixes sticky element glitch #2303

merged 1 commit into from
Nov 26, 2021

Conversation

andysellick
Copy link
Contributor

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

Fixes #2297

The sticky element was 'flashing' when positioned at the bottom of the area. This was due to the element being constantly switched between the sticky and non-sticky states.

This was an interesting bug. There is a function called on scroll that sets this.hasScrolled and a second function checkScroll called on an interval that checks to see if this.hasScrolled is true, updates the sticky element as appropriate, then sets it back to false, ready for the next scroll.

The function checkResize checks and then sets the equivalent this.hasResized to false. checkResize also sets this.hasScrolled to true, in order to trigger checkScroll (because resizing can change the height of the page). A change to make this code fit our module pattern had updated checkScroll to also set this.hasResized to true (to match checkResize). Unfortunately this had the effect of both functions constantly triggering each other. Unnoticed, the functions attached to the window scroll and resize events hadn't had the proper .bind(this) applied, which meant that the code was seemingly working, but not at all as expected.

Example pages:

Why

Visual changes

None.

@govuk-ci govuk-ci temporarily deployed to government-f-fix-sticky-s7uc6v November 26, 2021 09:17 Inactive
Copy link
Contributor

@gclssvglx gclssvglx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @andysellick 👍 - thank you so much for fixing this 🙏

@andysellick andysellick merged commit 0940ef7 into main Nov 26, 2021
@andysellick andysellick deleted the fix-sticky-js branch November 26, 2021 09:27
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

Successfully merging this pull request may close these issues.

Back to top component flashing
3 participants