The problem is not quite exact, for example if there’s a heading and then a text, the idea is that only when the text of a heading is completely offscreen, then detect the next heading as the current one in the table of contents…
In the image above it should detect “setup” instead of “Javascript”
should be easy enough.
Instead of having id’s on headings have the id’s in the paragraphs instead.
I noticed that some sections have multiple paragraphs.
What I would do is to create a new element let’s say for setup
Thanks, well creating sections would just create me other problemas alongised the extra manual work so I’m afriad is not feasible. I’m wondering what about observing p elements as well, but only if no headings are intersecting? and then look for the closest heading of this paragraph?
some of your headings may have 1 or more paragraphs underneath, programmatically you need to have some detectable boundaries.
The current boundaries are the heading elements with the ids set.
that should work, using classes so is not messing up the href’s from the menu on click.
I am too exhausted today to dig deeper but I am almost sure there is a better way to handle this.