2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-05 16:42:29 +03:00

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:

```
<section id="animals">
  <section id="dogs">
	Content
  </section>
</section>
```

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.
This commit is contained in:
Caden Lovelace
2015-01-17 01:14:22 +00:00
parent 984204c39e
commit a1aa0f8afd
2 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -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])
}
}