mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-30 22:52:24 +01:00
fixes #10236
if affixed top add scrollTop to it position.top calculate and cache pinnedoffset independent of scrolling for initial load
This commit is contained in:
parent
1fc08c1973
commit
50bd4edb8c
19
dist/js/bootstrap.js
vendored
19
dist/js/bootstrap.js
vendored
@ -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('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))
|
||||||
|
|
||||||
this.$element = $(element)
|
this.$element = $(element)
|
||||||
this.affixed =
|
this.affixed =
|
||||||
this.unpin = null
|
this.unpin =
|
||||||
|
this.pinnedOffset = null
|
||||||
|
|
||||||
this.checkPosition()
|
this.checkPosition()
|
||||||
}
|
}
|
||||||
@ -1791,6 +1792,14 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
|
|||||||
offset: 0
|
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 () {
|
Affix.prototype.checkPositionWithEventLoop = function () {
|
||||||
setTimeout($.proxy(this.checkPosition, this), 1)
|
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 offsetTop = offset.top
|
||||||
var offsetBottom = offset.bottom
|
var offsetBottom = offset.bottom
|
||||||
|
|
||||||
|
if (this.affixed == 'top') position.top += scrollTop
|
||||||
|
|
||||||
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
||||||
if (typeof offsetTop == 'function') offsetTop = offset.top()
|
if (typeof offsetTop == 'function') offsetTop = offset.top()
|
||||||
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
|
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', '')
|
if (this.unpin) this.$element.css('top', '')
|
||||||
|
|
||||||
this.affixed = affix
|
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 : ''))
|
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))
|
||||||
|
|
||||||
|
2
dist/js/bootstrap.min.js
vendored
2
dist/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
19
js/affix.js
19
js/affix.js
@ -18,9 +18,10 @@
|
|||||||
.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))
|
||||||
|
|
||||||
this.$element = $(element)
|
this.$element = $(element)
|
||||||
this.affixed =
|
this.affixed =
|
||||||
this.unpin = null
|
this.unpin =
|
||||||
|
this.pinnedOffset = null
|
||||||
|
|
||||||
this.checkPosition()
|
this.checkPosition()
|
||||||
}
|
}
|
||||||
@ -31,6 +32,14 @@
|
|||||||
offset: 0
|
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 () {
|
Affix.prototype.checkPositionWithEventLoop = function () {
|
||||||
setTimeout($.proxy(this.checkPosition, this), 1)
|
setTimeout($.proxy(this.checkPosition, this), 1)
|
||||||
}
|
}
|
||||||
@ -45,6 +54,8 @@
|
|||||||
var offsetTop = offset.top
|
var offsetTop = offset.top
|
||||||
var offsetBottom = offset.bottom
|
var offsetBottom = offset.bottom
|
||||||
|
|
||||||
|
if (this.affixed == 'top') position.top += scrollTop
|
||||||
|
|
||||||
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
||||||
if (typeof offsetTop == 'function') offsetTop = offset.top()
|
if (typeof offsetTop == 'function') offsetTop = offset.top()
|
||||||
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
|
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
|
||||||
@ -57,7 +68,7 @@
|
|||||||
if (this.unpin) this.$element.css('top', '')
|
if (this.unpin) this.$element.css('top', '')
|
||||||
|
|
||||||
this.affixed = affix
|
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 : ''))
|
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user