Skip to content

Commit

Permalink
fix affix…
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Jul 26, 2013
1 parent 124d7e6 commit f5f04ae
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
18 changes: 14 additions & 4 deletions assets/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ input.focused {
right: 15px;
bottom: 15px;
}

.bs-header {
font-size: 21px;
text-align: left;
Expand Down Expand Up @@ -793,12 +792,22 @@ input.focused {
@media screen and (min-width: 992px) {

/* Widen the fixed sidebar */
.bs-sidebar.affix,
.bs-sidebar.affix-bottom {
width: 213px;
}
.bs-sidebar.affix {
position: fixed; /* Undo the static from mobile-first approach */
top: 50px;
width: 213px;
top: 80px;
}
.bs-sidebar.affix-bottom {
position: absolute; /* Undo the static from mobile-first approach */
}
.bs-sidebar.affix-bottom .bs-sidenav,
.bs-sidebar.affix .bs-sidenav {
margin-top: 0;
margin-bottom: 0;
}

.bs-header h1,
.bs-header p {
margin-right: 380px;
Expand All @@ -818,6 +827,7 @@ input.focused {
@media screen and (min-width: 1200px) {

/* Widen the fixed sidebar again */
.bs-sidebar.affix-bottom,
.bs-sidebar.affix {
width: 270px;
}
Expand Down
17 changes: 14 additions & 3 deletions assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
e.preventDefault()
})


// back to top
setTimeout(function () {
$('.bs-sidebar').affix({
var $sideBar = $('.bs-sidebar')

$sideBar.affix({
offset: {
top: function () { return $window.width() <= 980 ? 290 : 210 }
, bottom: 270
top: function () {
var offsetTop = $sideBar.offset().top
var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10)
var navOuterHeight = $('.bs-docs-nav').height()

return (this.top = offsetTop - navOuterHeight - sideBarMargin)
}
, bottom: function () {
return (this.bottom = $('.bs-footer').outerHeight(true))
}
}
})
}, 100)
Expand Down
10 changes: 8 additions & 2 deletions dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,8 @@ if (!jQuery) throw new Error("Bootstrap requires jQuery")
this.checkPosition()
}

Affix.RESET = 'affix affix-top affix-bottom'

Affix.DEFAULTS = {
offset: 0
}
Expand All @@ -1859,7 +1861,6 @@ if (!jQuery) throw new Error("Bootstrap requires jQuery")
var offset = this.options.offset
var offsetTop = offset.top
var offsetBottom = offset.bottom
var reset = 'affix affix-top affix-bottom'

if (typeof offset != 'object') offsetBottom = offsetTop = offset
if (typeof offsetTop == 'function') offsetTop = offset.top()
Expand All @@ -1870,11 +1871,16 @@ if (!jQuery) throw new Error("Bootstrap requires jQuery")
offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false

if (this.affixed === affix) return
if (this.unpin) this.$element.css('top', '')

this.affixed = affix
this.unpin = affix == 'bottom' ? position.top - scrollTop : null

this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))

if (affix == 'bottom') {
this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() })
}
}


Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions js/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
this.checkPosition()
}

Affix.RESET = 'affix affix-top affix-bottom'

Affix.DEFAULTS = {
offset: 0
}
Expand All @@ -53,7 +55,6 @@
var offset = this.options.offset
var offsetTop = offset.top
var offsetBottom = offset.bottom
var reset = 'affix affix-top affix-bottom'

if (typeof offset != 'object') offsetBottom = offsetTop = offset
if (typeof offsetTop == 'function') offsetTop = offset.top()
Expand All @@ -64,11 +65,16 @@
offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false

if (this.affixed === affix) return
if (this.unpin) this.$element.css('top', '')

this.affixed = affix
this.unpin = affix == 'bottom' ? position.top - scrollTop : null

this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))

if (affix == 'bottom') {
this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() })
}
}


Expand Down

0 comments on commit f5f04ae

Please sign in to comment.