1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-12 00:24:03 +02:00

refactor scrollspy refresh method

Closes #13702 by merging a rebased version of it.
This commit is contained in:
Mike Greiling
2014-05-29 02:51:49 -05:00
committed by Chris Rebert
parent bc8e6ffb7d
commit 1cfa902e31

View File

@@ -36,7 +36,13 @@
} }
ScrollSpy.prototype.refresh = function () { ScrollSpy.prototype.refresh = function () {
var offsetMethod = this.$scrollElement[0] == window ? 'offset' : 'position' var offsetMethod = 'offset'
var offsetBase = 0
if (!$.isWindow(this.$scrollElement[0])) {
offsetMethod = 'position'
offsetBase = this.$scrollElement.scrollTop()
}
this.offsets = [] this.offsets = []
this.targets = [] this.targets = []
@@ -54,7 +60,7 @@
return ($href return ($href
&& $href.length && $href.length
&& $href.is(':visible') && $href.is(':visible')
&& [[$href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href]]) || null && [[$href[offsetMethod]().top + offsetBase, href]]) || null
}) })
.sort(function (a, b) { return a[0] - b[0] }) .sort(function (a, b) { return a[0] - b[0] })
.each(function () { .each(function () {