diff --git a/docs/javascript.html b/docs/javascript.html index fb854d2814..1b8af662af 100644 --- a/docs/javascript.html +++ b/docs/javascript.html @@ -549,7 +549,7 @@ $('#myModal').on('hidden', function () { -
+

@fat

Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat. @@ -576,11 +576,30 @@ $('#myModal').on('hidden', function () {


Using bootstrap-scrollspy.js

Call the scrollspy via javascript:

-
$('#navbar').dropdown()
+
$('#navbar').scrollspy()

Markup

To easily add scrollspy behavior to your topbar navigation, just add data-spy="scroll" to the element you want to spy on (most typically this would be the body).

<body data-spy="scroll" >...</body>

Notice Navbar anchor tags must have resolvable id targets. For example, a <a href="#home">home</a> must correspond to something in the dom like <div id="home"></div>. +

Options

+ + + + + + + + + + + + + + + + + +
Nametypedefaultdescription
offsetnumber10Pixels to offset from top when calculating position of scroll.
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 63195b4bdf..5049bfdf95 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