mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-20 17:54:23 +01:00
Merge pull request #15913 from twbs/scrollspy-consistency
ScrollSpy: Small style consistency adjustments
This commit is contained in:
commit
9ea98561df
@ -14,10 +14,8 @@
|
|||||||
// ==========================
|
// ==========================
|
||||||
|
|
||||||
function ScrollSpy(element, options) {
|
function ScrollSpy(element, options) {
|
||||||
var process = $.proxy(this.process, this)
|
this.$body = $(document.body)
|
||||||
|
this.$scrollElement = $(element).is(document.body) ? $(window) : $(element)
|
||||||
this.$body = $('body')
|
|
||||||
this.$scrollElement = $(element).is('body') ? $(window) : $(element)
|
|
||||||
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
||||||
this.selector = (this.options.target || '') + ' .nav li > a'
|
this.selector = (this.options.target || '') + ' .nav li > a'
|
||||||
this.offsets = []
|
this.offsets = []
|
||||||
@ -25,7 +23,7 @@
|
|||||||
this.activeTarget = null
|
this.activeTarget = null
|
||||||
this.scrollHeight = 0
|
this.scrollHeight = 0
|
||||||
|
|
||||||
this.$scrollElement.on('scroll.bs.scrollspy', process)
|
this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this))
|
||||||
this.refresh()
|
this.refresh()
|
||||||
this.process()
|
this.process()
|
||||||
}
|
}
|
||||||
@ -41,19 +39,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScrollSpy.prototype.refresh = function () {
|
ScrollSpy.prototype.refresh = function () {
|
||||||
|
var that = this
|
||||||
var offsetMethod = 'offset'
|
var offsetMethod = 'offset'
|
||||||
var offsetBase = 0
|
var offsetBase = 0
|
||||||
|
|
||||||
if (!$.isWindow(this.$scrollElement[0])) {
|
|
||||||
offsetMethod = 'position'
|
|
||||||
offsetBase = this.$scrollElement.scrollTop()
|
|
||||||
}
|
|
||||||
|
|
||||||
this.offsets = []
|
this.offsets = []
|
||||||
this.targets = []
|
this.targets = []
|
||||||
this.scrollHeight = this.getScrollHeight()
|
this.scrollHeight = this.getScrollHeight()
|
||||||
|
|
||||||
var self = this
|
if (!$.isWindow(this.$scrollElement[0])) {
|
||||||
|
offsetMethod = 'position'
|
||||||
|
offsetBase = this.$scrollElement.scrollTop()
|
||||||
|
}
|
||||||
|
|
||||||
this.$body
|
this.$body
|
||||||
.find(this.selector)
|
.find(this.selector)
|
||||||
@ -69,8 +66,8 @@
|
|||||||
})
|
})
|
||||||
.sort(function (a, b) { return a[0] - b[0] })
|
.sort(function (a, b) { return a[0] - b[0] })
|
||||||
.each(function () {
|
.each(function () {
|
||||||
self.offsets.push(this[0])
|
that.offsets.push(this[0])
|
||||||
self.targets.push(this[1])
|
that.targets.push(this[1])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user