Re: Is there a way to autoscroll the toc from the content in HTML
Posted by
mojavelinux on
URL: https://discuss.asciidoctor.org/Is-there-a-way-to-autoscroll-the-toc-from-the-content-in-HTML-tp4525p4530.html
Antoine,
This feature is certainly achievable and something I agree would make navigating large documents much easier.
Implementing this feature involves adding some JavaScript to the page. You can add the necessary JavaScript right now using a docinfo file (or docinfo extension). This is particularly feasible since all the sections have IDs by default and the entries in the TOC refer to those IDs. The only thing left to do is coordinate the scroll position to one of the entries by toggling a CSS class.
The common name for this feature is "scroll spy". There are numerous libraries available that implement it. The one from Foundation is called Magellen {1}. If we decided to integrate this feature into core, we'll probably write something custom.
I think the next step is to implement a prototype which we can put into the extensions lab (as a docinfo extension). We can refine it there, then sort out the best way to integrate it into core, if we decide it should go there.
Here are a couple of examples for reference:
If anyone has other reference examples, I encourage you to post them.
-Dan