0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-18 10:52:19 +01:00
if affixed top add scrollTop to it position.top
calculate and cache pinnedoffset independent of scrolling for initial load
This commit is contained in:
fat 2013-12-24 12:32:06 -08:00
parent 1fc08c1973
commit 50bd4edb8c
4 changed files with 32 additions and 10 deletions

19
dist/js/bootstrap.js vendored
View File

@ -1778,9 +1778,10 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
.on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
this.$element = $(element)
this.affixed =
this.unpin = null
this.$element = $(element)
this.affixed =
this.unpin =
this.pinnedOffset = null
this.checkPosition()
}
@ -1791,6 +1792,14 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
offset: 0
}
Affix.prototype.getPinnedOffset = function () {
if (this.pinnedOffset) return this.pinnedOffset
this.$element.removeClass(Affix.RESET).addClass('affix')
var scrollTop = this.$window.scrollTop()
var position = this.$element.offset()
return (this.pinnedOffset = position.top - scrollTop)
}
Affix.prototype.checkPositionWithEventLoop = function () {
setTimeout($.proxy(this.checkPosition, this), 1)
}
@ -1805,6 +1814,8 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
var offsetTop = offset.top
var offsetBottom = offset.bottom
if (this.affixed == 'top') position.top += scrollTop
if (typeof offset != 'object') offsetBottom = offsetTop = offset
if (typeof offsetTop == 'function') offsetTop = offset.top()
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
@ -1817,7 +1828,7 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
if (this.unpin) this.$element.css('top', '')
this.affixed = affix
this.unpin = affix == 'bottom' ? position.top - scrollTop : null
this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,9 +18,10 @@
.on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
this.$element = $(element)
this.affixed =
this.unpin = null
this.$element = $(element)
this.affixed =
this.unpin =
this.pinnedOffset = null
this.checkPosition()
}
@ -31,6 +32,14 @@
offset: 0
}
Affix.prototype.getPinnedOffset = function () {
if (this.pinnedOffset) return this.pinnedOffset
this.$element.removeClass(Affix.RESET).addClass('affix')
var scrollTop = this.$window.scrollTop()
var position = this.$element.offset()
return (this.pinnedOffset = position.top - scrollTop)
}
Affix.prototype.checkPositionWithEventLoop = function () {
setTimeout($.proxy(this.checkPosition, this), 1)
}
@ -45,6 +54,8 @@
var offsetTop = offset.top
var offsetBottom = offset.bottom
if (this.affixed == 'top') position.top += scrollTop
if (typeof offset != 'object') offsetBottom = offsetTop = offset
if (typeof offsetTop == 'function') offsetTop = offset.top()
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
@ -57,7 +68,7 @@
if (this.unpin) this.$element.css('top', '')
this.affixed = affix
this.unpin = affix == 'bottom' ? position.top - scrollTop : null
this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))