Created by: neoeno
When the first two elements tracked by Scrollspy have an offset.top
of 0, Scrollspy will flip between activating their respective nav events on every scroll event. This causes a visual 'flicker', and heavily degrades scroll performance.
Examples: Minimal example. Example with nested sections.
I saw this happen in a system of nested sections positioned hard against the top of the document, e.g.
<section id="animals">
<section id="dogs">
Content
</section>
</section>
The bug is that Scrollspy's check to see if it's at the end of the array of sections uses !arr[index + 1]
. This misses the case where arr[index + 1]
does exist and is zero.
This commit explicitly checks the array bounds. A unit test is included, but I'm not familiar with bootstrap's testing approach so feedback is appreciated.
(Thanks go to @theroux and @tnguyen14!)