aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <[email protected]>2014-05-29 02:51:49 -0500
committerChris Rebert <[email protected]>2014-06-07 18:26:39 -0700
commit1cfa902e313e848732976ac6e538f3f72c135d90 (patch)
tree4bcbab814dc819a557fb4f1ad6e9f57569624845
parentbc8e6ffb7d702895296050d2fd8847fb5eed2381 (diff)
downloadbootstrap-1cfa902e313e848732976ac6e538f3f72c135d90.tar.xz
bootstrap-1cfa902e313e848732976ac6e538f3f72c135d90.zip
refactor scrollspy refresh method
Closes #13702 by merging a rebased version of it.
-rw-r--r--js/scrollspy.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js
index 94171bb1b..644c65f94 100644
--- a/js/scrollspy.js
+++ b/js/scrollspy.js
@@ -36,7 +36,13 @@
}
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.targets = []
@@ -54,7 +60,7 @@
return ($href
&& $href.length
&& $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] })
.each(function () {