diff options
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/scrollspy.js | 21 |
1 files changed, 14 insertions, 7 deletions
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 = [] |
