From da495ee24c239ef9c9c154670b1a641745ac147f Mon Sep 17 00:00:00 2001 From: fat Date: Wed, 13 May 2015 12:55:11 -0700 Subject: address https://github.com/twbs/bootstrap/pull/16135 --- js/src/scrollspy.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'js/src') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index d1be3a45f..3f4a145a1 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -25,7 +25,8 @@ const ScrollSpy = (($) => { const JQUERY_NO_CONFLICT = $.fn[NAME] const Default = { - offset : 10 + offset : 10, + method : 'auto' } const Event = { @@ -46,6 +47,11 @@ const ScrollSpy = (($) => { LI : 'li' } + const OffsetMethod = { + OFFSET : 'offset', + POSITION : 'position' + } + /** * ------------------------------------------------------------------------ @@ -86,13 +92,14 @@ const ScrollSpy = (($) => { // public refresh() { - let offsetMethod = 'offset' - let offsetBase = 0 + let autoMethod = this._scrollElement !== this._scrollElement.window ? + OffsetMethod.POSITION : OffsetMethod.OFFSET - if (this._scrollElement !== this._scrollElement.window) { - offsetMethod = 'position' - offsetBase = this._getScrollTop() - } + let offsetMethod = this._config.method === 'auto' ? + autoMethod : this._config.method + + let offsetBase = offsetMethod === OffsetMethod.POSITION ? + this._getScrollTop() : 0 this._offsets = [] this._targets = [] -- cgit v1.2.3