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

fix: When scrolling to an anchor, account for the header height (fixes #146) #158

Merged
merged 4 commits into from
May 18, 2020

Conversation

palant
Copy link
Collaborator

@palant palant commented May 17, 2020

This implements the work-around described in #146. Since the header height has to be known, this will do an approximate calculation of the header height in CSS (already works well enough for me under most circumstances). The header will then be measured precisely by JavaScript if enabled.

@@ -18,6 +18,16 @@ if (mainInner !== null) {
headerInner.style.setProperty('opacity', 1);


// Measure header height for the scrolling fix
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The block here is necessary to avoid declaring constants at the top level of the script - this will conflict with another declaration of const header elsewhere. It might generally be a good idea to wrap each script file in a block to give it its own scope - this will make sure there are no conflicts between declarations in different script files.

@reuixiy reuixiy self-requested a review May 18, 2020 00:55
);

/* Work-around for anchors being hidden below the header */
p, div, ul, form, main, footer, nav, section, h1, h2, h3, h4, h5, h6
Copy link
Owner

Choose a reason for hiding this comment

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

Wait, I don't think we need to select so many elements - this may cause some bugs, such as the one I found on your site:

2020-05-18-14-03-40

So maybe just headings?

@reuixiy reuixiy self-requested a review May 18, 2020 06:12
@palant
Copy link
Collaborator Author

palant commented May 18, 2020

It isn't just headings - there is scrolling to footnotes and other elements as well. I shortened the list but I'm not quite happy with lists not being on there. Maybe a better solution would be limiting this to #main.

@reuixiy
Copy link
Owner

reuixiy commented May 18, 2020

Agreed. It would be better to limit this to #main.

@palant
Copy link
Collaborator Author

palant commented May 18, 2020

There you go, done.

@palant
Copy link
Collaborator Author

palant commented May 18, 2020

Noticed that I had all the rules defined within :root - this isn't necessary, fixed.

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.

2 participants