-
Notifications
You must be signed in to change notification settings - Fork 352
Description
A common feature in many websites with a lot of content is to have a "scroll to top" button that pops up when two conditions are met.
- The person has already scrolled down the page by some amount.
- The person starts to scroll upward.
I think this theme should support a similar kind of pattern, since many pages in the sphinx/python ecosystem have very long content. cc @trallard in case this also has accessibility implications.
Inspiration
For example:
mkdocs material:
furo:
Implementation
The way I've seen this done is to use a little "helper pixel" that is used to trigger a javascript event to detect condition 1, and then use a "scroll up" event to trigger condition 2.
For example, in the book theme we have something like this. Here is the little empty pixel div:
Here is the styling to make it invisible:
and here we set javascript to use an IntersectionObserver
event that triggers when the empty div scrolls off screen, and it adds a class called scrolled
to the page's body when it is triggered:
We could then add a "scroll up" event that would show the button if the body.scrolled
class is present, and a "scroll down" event that would hide the button if it is shown.