scrollnav icon indicating copy to clipboard operation
scrollnav copied to clipboard

Subsections in nested elements are not recognized

Open justlevine opened this issue 5 years ago • 2 comments

For some reason, only subsections in the same parent element are recognised by scrollnav. This is obviously not ideal behavior, as there are various reasons one might be nesting their subsections in a different element (e.g. lists).

Config:

scrollnav.init( content, {
	sections: 'h2',
	subSections: 'h3',
	insertLocation: 'prepend',
} );

Html

<section>
    <h2>Section Title</h2> <!--Will appear-->
    <ul>
        <li>
            <h3>Step 1</h3> <!-- Will NOT appear -->
            <p>Content goes here</p>
        </li>
    <ul>
</section>

Suggestions on how to fix?

justlevine avatar Sep 22 '19 14:09 justlevine

I use a nextUntil function to search for the subsections that only looks at elems on the same level. I did this to try and speed up the dom query but I'll have to rethink it. Thanks for opening the bug.

jimmynotjim avatar Oct 04 '19 17:10 jimmynotjim

I did come across the same issue. I "solved" this behaviour, repeating the headings on the expected level and hide the duplicates using visibility:hidden (display:none shows heading in nav, but does not scroll to correct position). Works for me.

makrohard avatar Jan 24 '21 23:01 makrohard