diff options
| author | fat <[email protected]> | 2013-07-26 22:24:51 -0700 |
|---|---|---|
| committer | fat <[email protected]> | 2013-07-26 22:24:51 -0700 |
| commit | cfa4ab90f3d8de9dd419a6b30f0ba57c9b9ba518 (patch) | |
| tree | cf07ce4c6b7806f915cc6c5ae644eb3f70fc39aa /js | |
| parent | 2cf1851d9f9ea73a9c2e446db88f5c2179ea2f40 (diff) | |
| download | bootstrap-cfa4ab90f3d8de9dd419a6b30f0ba57c9b9ba518.tar.xz bootstrap-cfa4ab90f3d8de9dd419a6b30f0ba57c9b9ba518.zip | |
fix scrollspy for window *and* children
Diffstat (limited to 'js')
| -rw-r--r-- | js/scrollspy.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/js/scrollspy.js b/js/scrollspy.js index e958021ed..10f95f249 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -26,10 +26,10 @@ function ScrollSpy(element, options) { var href var process = $.proxy(this.process, this) - var $element = $(element).is('body') ? $(window) : $(element) + this.$element = $(element).is('body') ? $(window) : $(element) this.$body = $('body') - this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process) + this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process) this.options = $.extend({}, ScrollSpy.DEFAULTS, options) this.selector = (this.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 @@ -47,6 +47,8 @@ } ScrollSpy.prototype.refresh = function () { + var offsetMethod = this.$element[0] == window ? 'offset' : 'position' + this.offsets = $([]) this.targets = $([]) @@ -60,7 +62,7 @@ return ($href && $href.length - && [[ $href.offset().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null + && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { |
