mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-20 17:54:23 +01:00
Merge branch 'impl-13342'; Closes #13342.
This commit is contained in:
commit
e44f5b15b1
@ -62,6 +62,13 @@
|
|||||||
<td>10</td>
|
<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>
|
<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>
|
||||||
|
<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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div><!-- /.table-responsive -->
|
</div><!-- /.table-responsive -->
|
||||||
|
10
js/affix.js
10
js/affix.js
@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
var Affix = function (element, options) {
|
var Affix = function (element, options) {
|
||||||
this.options = $.extend({}, Affix.DEFAULTS, 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('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
|
||||||
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
|
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
|
||||||
|
|
||||||
@ -32,13 +33,14 @@
|
|||||||
Affix.RESET = 'affix affix-top affix-bottom'
|
Affix.RESET = 'affix affix-top affix-bottom'
|
||||||
|
|
||||||
Affix.DEFAULTS = {
|
Affix.DEFAULTS = {
|
||||||
offset: 0
|
offset: 0,
|
||||||
|
target: window
|
||||||
}
|
}
|
||||||
|
|
||||||
Affix.prototype.getPinnedOffset = function () {
|
Affix.prototype.getPinnedOffset = function () {
|
||||||
if (this.pinnedOffset) return this.pinnedOffset
|
if (this.pinnedOffset) return this.pinnedOffset
|
||||||
this.$element.removeClass(Affix.RESET).addClass('affix')
|
this.$element.removeClass(Affix.RESET).addClass('affix')
|
||||||
var scrollTop = this.$window.scrollTop()
|
var scrollTop = this.$target.scrollTop()
|
||||||
var position = this.$element.offset()
|
var position = this.$element.offset()
|
||||||
return (this.pinnedOffset = position.top - scrollTop)
|
return (this.pinnedOffset = position.top - scrollTop)
|
||||||
}
|
}
|
||||||
@ -51,7 +53,7 @@
|
|||||||
if (!this.$element.is(':visible')) return
|
if (!this.$element.is(':visible')) return
|
||||||
|
|
||||||
var scrollHeight = $(document).height()
|
var scrollHeight = $(document).height()
|
||||||
var scrollTop = this.$window.scrollTop()
|
var scrollTop = this.$target.scrollTop()
|
||||||
var position = this.$element.offset()
|
var position = this.$element.offset()
|
||||||
var offset = this.options.offset
|
var offset = this.options.offset
|
||||||
var offsetTop = offset.top
|
var offsetTop = offset.top
|
||||||
|
Loading…
x
Reference in New Issue
Block a user