mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
fix #13220 Scrollspy generates wrong offsets for a page-- recalculate offsets if scrollheight
changes
This commit is contained in:
parent
8d8524e594
commit
571fd32bce
1 changed files with 11 additions and 1 deletions
|
@ -27,6 +27,7 @@
|
||||||
this.offsets = []
|
this.offsets = []
|
||||||
this.targets = []
|
this.targets = []
|
||||||
this.activeTarget = null
|
this.activeTarget = null
|
||||||
|
this.scrollHeight = 0
|
||||||
|
|
||||||
this.$scrollElement.on('scroll.bs.scrollspy', process)
|
this.$scrollElement.on('scroll.bs.scrollspy', process)
|
||||||
this.refresh()
|
this.refresh()
|
||||||
|
@ -39,6 +40,10 @@
|
||||||
offset: 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 () {
|
ScrollSpy.prototype.refresh = function () {
|
||||||
var offsetMethod = 'offset'
|
var offsetMethod = 'offset'
|
||||||
var offsetBase = 0
|
var offsetBase = 0
|
||||||
|
@ -50,6 +55,7 @@
|
||||||
|
|
||||||
this.offsets = []
|
this.offsets = []
|
||||||
this.targets = []
|
this.targets = []
|
||||||
|
this.scrollHeight = this.getScrollHeight()
|
||||||
|
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
|
@ -74,13 +80,17 @@
|
||||||
|
|
||||||
ScrollSpy.prototype.process = function () {
|
ScrollSpy.prototype.process = function () {
|
||||||
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
|
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 maxScroll = this.options.offset + scrollHeight - this.$scrollElement.height()
|
||||||
var offsets = this.offsets
|
var offsets = this.offsets
|
||||||
var targets = this.targets
|
var targets = this.targets
|
||||||
var activeTarget = this.activeTarget
|
var activeTarget = this.activeTarget
|
||||||
var i
|
var i
|
||||||
|
|
||||||
|
if (this.scrollHeight != scrollHeight) {
|
||||||
|
this.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
if (scrollTop >= maxScroll) {
|
if (scrollTop >= maxScroll) {
|
||||||
return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
|
return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue