aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-05-16 14:30:31 -0700
committerChris Rebert <[email protected]>2014-05-16 14:30:31 -0700
commite44f5b15b1330b00f62eb8bf5dc923b31f869995 (patch)
tree6ba0940e6d71e48e2e75a34ce51c7ff7cb006736
parenta40ff40b8fb852af8034b215e2102ca8ff1618e0 (diff)
parentf47ad79538458c4fe787335a5873c00073c5c2c9 (diff)
downloadbootstrap-e44f5b15b1330b00f62eb8bf5dc923b31f869995.tar.xz
bootstrap-e44f5b15b1330b00f62eb8bf5dc923b31f869995.zip
Merge branch 'impl-13342'; Closes #13342.
-rw-r--r--docs/_includes/js/affix.html7
-rw-r--r--js/affix.js10
2 files changed, 13 insertions, 4 deletions
diff --git a/docs/_includes/js/affix.html b/docs/_includes/js/affix.html
index cfd32ec35..5b6fec0bb 100644
--- a/docs/_includes/js/affix.html
+++ b/docs/_includes/js/affix.html
@@ -62,6 +62,13 @@
<td>10</td>
<td>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 <code>offset: { top: 10 }</code> or <code>offset: { top: 10, bottom: 5 }</code>. Use a function when you need to dynamically calculate an offset.</td>
</tr>
+ <tr>
+ <td>target</td>
+ <td>selector | node | jQuery element</td>
+ <td>the <code>window</code> object</td>
+ <td>Specifies the target element of the affix.</td>
+ </tr>
+
</tbody>
</table>
</div><!-- /.table-responsive -->
diff --git a/js/affix.js b/js/affix.js
index fc91936fb..c7e1b797e 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