From a1aa0f8afdc33403604e5415aed649e605e93efd Mon Sep 17 00:00:00 2001 From: Caden Lovelace Date: Sat, 17 Jan 2015 01:14:22 +0000 Subject: Handle multiple zero-offset Scrollspy elements. When the first two elements in a scrollspy content block have a document offset of zero (i.e. they're hard against the top of the page), Scrollspy would switch between them on every scroll event. This could happen, for example, in a system of nested sections: ```
Content
``` This ocurred because Scrollspy's check to see if it's at the end of the array of sections uses `!arr[index]`. This misses the case where `arr[index]` does exist and is zero. This commit explicitly checks the array bounds. --- js/scrollspy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/scrollspy.js') diff --git a/js/scrollspy.js b/js/scrollspy.js index a72bb5350..9b29edf49 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -96,7 +96,7 @@ for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] - && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) + && (offsets[i + 1] === undefined || scrollTop <= offsets[i + 1]) && this.activate(targets[i]) } } -- cgit v1.2.3