summaryrefslogtreecommitdiff
path: root/js/application.js
diff options
context:
space:
mode:
authorThomas Park <thomas@thomaspark.me>2013-02-07 17:15:05 -0500
committerThomas Park <thomas@thomaspark.me>2013-02-07 17:15:05 -0500
commitf750ad35ded1e976abb6f40d6f9ed4afe3be03d3 (patch)
treed0a603aea8421f6b169681b25156e59c1f7d7d11 /js/application.js
parent14dc685d89bbbdfa50ebc09916f466570994cc19 (diff)
preview pages: get rid of content jumps when subnav -> subnav-fixed
Diffstat (limited to 'js/application.js')
-rwxr-xr-xjs/application.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/js/application.js b/js/application.js
index cd7cf0c9..8daeebf6 100755
--- a/js/application.js
+++ b/js/application.js
@@ -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();
@@ -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');
}
}