mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-21 20:55:50 +02:00
Merge branch 'mikegreiling-scrollspy-update'
This commit is contained in:
@@ -14,20 +14,17 @@
|
|||||||
// ==========================
|
// ==========================
|
||||||
|
|
||||||
function ScrollSpy(element, options) {
|
function ScrollSpy(element, options) {
|
||||||
var href
|
|
||||||
var process = $.proxy(this.process, this)
|
var process = $.proxy(this.process, this)
|
||||||
|
|
||||||
this.$element = $(element).is('body') ? $(window) : $(element)
|
|
||||||
this.$body = $('body')
|
this.$body = $('body')
|
||||||
this.$scrollElement = this.$element.on('scroll.bs.scrollspy', process)
|
this.$scrollElement = $(element).is('body') ? $(window) : $(element)
|
||||||
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
this.options = $.extend({}, ScrollSpy.DEFAULTS, options)
|
||||||
this.selector = (this.options.target
|
this.selector = (this.options.target || '') + ' .nav li > a'
|
||||||
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
this.offsets = []
|
||||||
|| '') + ' .nav li > a'
|
this.targets = []
|
||||||
this.offsets = $([])
|
|
||||||
this.targets = $([])
|
|
||||||
this.activeTarget = null
|
this.activeTarget = null
|
||||||
|
|
||||||
|
this.$scrollElement.on('scroll.bs.scrollspy', process)
|
||||||
this.refresh()
|
this.refresh()
|
||||||
this.process()
|
this.process()
|
||||||
}
|
}
|
||||||
@@ -39,10 +36,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScrollSpy.prototype.refresh = function () {
|
ScrollSpy.prototype.refresh = function () {
|
||||||
var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
|
var offsetMethod = 'offset'
|
||||||
|
var offsetBase = 0
|
||||||
|
|
||||||
|
if (!$.isWindow(this.$scrollElement[0])) {
|
||||||
|
offsetMethod = 'position'
|
||||||
|
offsetBase = this.$scrollElement.scrollTop()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.offsets = []
|
||||||
|
this.targets = []
|
||||||
|
|
||||||
this.offsets = $([])
|
|
||||||
this.targets = $([])
|
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
this.$body
|
this.$body
|
||||||
@@ -56,7 +60,7 @@
|
|||||||
return ($href
|
return ($href
|
||||||
&& $href.length
|
&& $href.length
|
||||||
&& $href.is(':visible')
|
&& $href.is(':visible')
|
||||||
&& [[$href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href]]) || null
|
&& [[$href[offsetMethod]().top + offsetBase, href]]) || null
|
||||||
})
|
})
|
||||||
.sort(function (a, b) { return a[0] - b[0] })
|
.sort(function (a, b) { return a[0] - b[0] })
|
||||||
.each(function () {
|
.each(function () {
|
||||||
@@ -75,7 +79,7 @@
|
|||||||
var i
|
var i
|
||||||
|
|
||||||
if (scrollTop >= maxScroll) {
|
if (scrollTop >= maxScroll) {
|
||||||
return activeTarget != (i = targets.last()[0]) && this.activate(i)
|
return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeTarget && scrollTop <= offsets[0]) {
|
if (activeTarget && scrollTop <= offsets[0]) {
|
||||||
|
Reference in New Issue
Block a user