diff --git a/docs/_includes/js/affix.html b/docs/_includes/js/affix.html
index cfd32ec356..5b6fec0bb4 100644
--- a/docs/_includes/js/affix.html
+++ b/docs/_includes/js/affix.html
@@ -62,6 +62,13 @@
10 |
Pixels to offset from screen when calculating position of scroll. If a single number is provided, the offset will be applied in both top and bottom directions. To provide a unique, bottom and top offset just provide an object offset: { top: 10 } or offset: { top: 10, bottom: 5 } . Use a function when you need to dynamically calculate an offset. |
+
+ target |
+ selector | node | jQuery element |
+ the window object |
+ Specifies the target element of the affix. |
+
+
diff --git a/js/affix.js b/js/affix.js
index fc91936fbd..c7e1b797e1 100644
--- a/js/affix.js
+++ b/js/affix.js
@@ -15,7 +15,8 @@
var Affix = function (element, options) {
this.options = $.extend({}, Affix.DEFAULTS, options)
- this.$window = $(window)
+
+ this.$target = $(this.options.target)
.on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
@@ -32,13 +33,14 @@
Affix.RESET = 'affix affix-top affix-bottom'
Affix.DEFAULTS = {
- offset: 0
+ offset: 0,
+ target: window
}
Affix.prototype.getPinnedOffset = function () {
if (this.pinnedOffset) return this.pinnedOffset
this.$element.removeClass(Affix.RESET).addClass('affix')
- var scrollTop = this.$window.scrollTop()
+ var scrollTop = this.$target.scrollTop()
var position = this.$element.offset()
return (this.pinnedOffset = position.top - scrollTop)
}
@@ -51,7 +53,7 @@
if (!this.$element.is(':visible')) return
var scrollHeight = $(document).height()
- var scrollTop = this.$window.scrollTop()
+ var scrollTop = this.$target.scrollTop()
var position = this.$element.offset()
var offset = this.options.offset
var offsetTop = offset.top