Skip to content

Commit

Permalink
Add absolutely positioned wrapper to allow using position: sticky o…
Browse files Browse the repository at this point in the history
…n the sidebar

The previous code depended on adding the scroll position to the root element as a custom property.
This resulted in excessive style recalculation which made scrolling laggy.

The api pages, which use separate stylesheets, actually solve this in a good way, by using a grid to define the sidebar area to be next to the main area.

Making the same markup change here results in quite a bit of things needing to be updated.

This commits attempts to apply a similar fix in a non intrusive manner, allowing the page to keep on working the way it did otherwise, but already removing the big performance cost.
  • Loading branch information
Inwerpsel committed Aug 27, 2024
1 parent 40e7a05 commit ce28acc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions _includes/docs.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
layout: "page.njk"
---

<div class="fix" style="">
<aside id="toc">
<ul>
{% include "partials/_docs-nav.njk" %}
</ul>
</aside>
</div>
{{ content | safe }}

{% include "partials/_footer-docs.njk" %}
20 changes: 11 additions & 9 deletions assets/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ main {
position: relative;
}

@media (min-width: 1480px) {
.fix {
position: absolute;
right: 100%;
height: 100%;
min-width: 220px;
}
}

#toc {
font-size: 75%;

Expand All @@ -11,16 +20,9 @@ main {
}

@media (min-width: 1480px) {
position: fixed;
top: 11rem;
right: calc(var(--page-width) + var(--page-margin) + 1em);
position: sticky;
top: 1em;
width: fit-content;
max-width: calc(var(--page-margin) - 1em);
margin-left: 1em;

@supports (top: max(1em, 1px)) {
top: max(0em, 11rem - var(--scrolltop) * 1px);
}
}


Expand Down
4 changes: 0 additions & 4 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ if (location.pathname.indexOf("/docs/") > -1 && window.toc) {
import("./docs.js");
}

let root = document.documentElement;

styleCallouts();

document.addEventListener("scroll", evt => {
root.style.setProperty("--scrolltop", root.scrollTop);
}, {passive: true});

0 comments on commit ce28acc

Please sign in to comment.