Skip to content

Commit

Permalink
Merge pull request #13783 from twbs/fat-13220
Browse files Browse the repository at this point in the history
fix #13220
  • Loading branch information
mdo committed Jun 11, 2014
2 parents 97e0cd0 + 571fd32 commit e136ba0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion js/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
this.offsets = []
this.targets = []
this.activeTarget = null
this.scrollHeight = 0

this.$scrollElement.on('scroll.bs.scrollspy', process)
this.refresh()
Expand All @@ -39,6 +40,10 @@
offset: 10
}

ScrollSpy.prototype.getScrollHeight = function () {
return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
}

ScrollSpy.prototype.refresh = function () {
var offsetMethod = 'offset'
var offsetBase = 0
Expand All @@ -50,6 +55,7 @@

this.offsets = []
this.targets = []
this.scrollHeight = this.getScrollHeight()

var self = this

Expand All @@ -74,13 +80,17 @@

ScrollSpy.prototype.process = function () {
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
var scrollHeight = this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
var scrollHeight = this.getScrollHeight()
var maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height()
var offsets = this.offsets
var targets = this.targets
var activeTarget = this.activeTarget
var i

if (this.scrollHeight != scrollHeight) {
this.refresh()
}

if (scrollTop >= maxScroll) {
return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
}
Expand Down

0 comments on commit e136ba0

Please sign in to comment.