diff options
| author | Jacob Thornton <[email protected]> | 2012-01-21 21:35:20 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-01-21 21:35:20 -0800 |
| commit | 2187e0838f522c102a8b5104970a9f129cdd001a (patch) | |
| tree | 7d429062295f5142ddac443967ef8093d83be416 /js | |
| parent | 719713ca8730d92d3510e6d4a7cc542fd57fdeef (diff) | |
| download | bootstrap-2187e0838f522c102a8b5104970a9f129cdd001a.tar.xz bootstrap-2187e0838f522c102a8b5104970a9f129cdd001a.zip | |
change scrollspy offset to be option + fix typo in scrollspy
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-scrollspy.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 63195b4bd..5049bfdf9 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -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 )
\ No newline at end of file |
