Skip to content

Commit

Permalink
preview pages: get rid of content jumps when subnav -> subnav-fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspark committed Feb 7, 2013
1 parent 14dc685 commit f750ad3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions css/bootswatch.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ section {
font-size: 54px;
}

.subhead > div:first-child {
min-height: 200px;
}

.subnav {
margin-bottom: 60px;
width: 100%;
Expand Down
12 changes: 9 additions & 3 deletions js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

// fix sub nav on scroll
var $win = $(window),
$body = $('body'),
$nav = $('.subnav'),
navHeight = $('.navbar').first().height(),
navTop = $('.subnav').length && $('.subnav').offset().top - navHeight,
subnavHeight = $('.subnav').first().height(),
subnavTop = $('.subnav').length && $('.subnav').offset().top - navHeight,
marginTop = parseInt($body.css('margin-top'), 10);
isFixed = 0;

processScroll();
Expand All @@ -15,12 +18,15 @@

function processScroll() {
var i, scrollTop = $win.scrollTop();
if (scrollTop >= navTop && !isFixed) {

if (scrollTop >= subnavTop && !isFixed) {
isFixed = 1;
$nav.addClass('subnav-fixed');
} else if (scrollTop <= navTop && isFixed) {
$body.css('margin-top', marginTop + subnavHeight + 'px');
} else if (scrollTop <= subnavTop && isFixed) {
isFixed = 0;
$nav.removeClass('subnav-fixed');
$body.css('margin-top', marginTop + 'px');
}
}

Expand Down

0 comments on commit f750ad3

Please sign in to comment.