mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 00:54:04 +02:00
change scrollspy offset to be option + fix typo in scrollspy
This commit is contained in:
19
js/bootstrap-scrollspy.js
vendored
19
js/bootstrap-scrollspy.js
vendored
@@ -24,15 +24,14 @@
|
||||
/* SCROLLSPY CLASS DEFINITION
|
||||
* ========================== */
|
||||
|
||||
function ScrollSpy( element ) {
|
||||
function ScrollSpy( element, options) {
|
||||
var process = $.proxy(this.process, this)
|
||||
|
||||
this.options = $.extend({}, $.fn.scrollspy.defaults, options)
|
||||
this.$scrollElement = $(element).on('scroll.scroll.data-api', process)
|
||||
this.selector = (this.$scrollElement.attr('data-target')
|
||||
|| this.$scrollElement.attr('href')
|
||||
|| '') + ' .nav li > a'
|
||||
this.$body = $('body').on('click.scroll.data-api', this.selector, process)
|
||||
|
||||
this.refresh()
|
||||
this.process()
|
||||
}
|
||||
@@ -55,7 +54,7 @@
|
||||
}
|
||||
|
||||
, process: function () {
|
||||
var scrollTop = this.$scrollElement.scrollTop() + 10
|
||||
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
|
||||
, offsets = this.offsets
|
||||
, targets = this.targets
|
||||
, activeTarget = this.activeTarget
|
||||
@@ -98,17 +97,25 @@
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
, data = $this.data('scrollspy')
|
||||
if (!data) $this.data('scrollspy', (data = new ScrollSpy(this)))
|
||||
, options = typeof option == 'object' && option
|
||||
if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options)))
|
||||
if (typeof option == 'string') data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
$.fn.scrollspy.Constructor = ScrollSpy
|
||||
|
||||
$.fn.scrollspy.defaults = {
|
||||
offset: 10
|
||||
}
|
||||
|
||||
|
||||
/* SCROLLSPY DATA-API
|
||||
* ============== */
|
||||
|
||||
$(function () { $('[data-spy="scroll"]').scrollspy() })
|
||||
$(function () {
|
||||
var $spy = $('[data-spy="scroll"]')
|
||||
$spy.scrollspy($spy.data())
|
||||
})
|
||||
|
||||
}( window.jQuery )
|
Reference in New Issue
Block a user