mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-17 09:52:29 +01:00
sort scrollspy to prevent flicker for unordered nav
This commit is contained in:
parent
94b24aaa47
commit
706ee46b73
Binary file not shown.
21
docs/assets/js/bootstrap-scrollspy.js
vendored
21
docs/assets/js/bootstrap-scrollspy.js
vendored
@ -43,16 +43,25 @@
|
||||
constructor: ScrollSpy
|
||||
|
||||
, refresh: function () {
|
||||
this.targets = this.$body
|
||||
var self = this
|
||||
, $targets
|
||||
|
||||
this.offsets = []
|
||||
this.targets = []
|
||||
|
||||
$targets = this.$body
|
||||
.find(this.selector)
|
||||
.map(function () {
|
||||
var href = $(this).attr('href')
|
||||
return /^#\w/.test(href) && $(href).length ? href : null
|
||||
return /^#\w/.test(href)
|
||||
&& $(href).length
|
||||
&& [[ $(href).position().top, href ]]
|
||||
})
|
||||
.sort(function (a, b) { return a[0] - b[0] })
|
||||
.each(function () {
|
||||
self.offsets.push(this[0])
|
||||
self.targets.push(this[1])
|
||||
})
|
||||
|
||||
this.offsets = $.map(this.targets, function (id) {
|
||||
return $(id).position().top
|
||||
})
|
||||
}
|
||||
|
||||
, process: function () {
|
||||
|
21
js/bootstrap-scrollspy.js
vendored
21
js/bootstrap-scrollspy.js
vendored
@ -43,16 +43,25 @@
|
||||
constructor: ScrollSpy
|
||||
|
||||
, refresh: function () {
|
||||
this.targets = this.$body
|
||||
var self = this
|
||||
, $targets
|
||||
|
||||
this.offsets = []
|
||||
this.targets = []
|
||||
|
||||
$targets = this.$body
|
||||
.find(this.selector)
|
||||
.map(function () {
|
||||
var href = $(this).attr('href')
|
||||
return /^#\w/.test(href) && $(href).length ? href : null
|
||||
return /^#\w/.test(href)
|
||||
&& $(href).length
|
||||
&& [[ $(href).position().top, href ]]
|
||||
})
|
||||
.sort(function (a, b) { return a[0] - b[0] })
|
||||
.each(function () {
|
||||
self.offsets.push(this[0])
|
||||
self.targets.push(this[1])
|
||||
})
|
||||
|
||||
this.offsets = $.map(this.targets, function (id) {
|
||||
return $(id).position().top
|
||||
})
|
||||
}
|
||||
|
||||
, process: function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user