From b204c20cdfbad20e7d7b7d4ee0a2b615f8716a7c Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 18 Jan 2017 14:59:39 -0500 Subject: [PATCH] Fixed stickynav bug --- js/stickynav.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/js/stickynav.js b/js/stickynav.js index 69dc217..553950d 100644 --- a/js/stickynav.js +++ b/js/stickynav.js @@ -1,33 +1,37 @@ jQuery(document).ready(function( $ ) { $(window).on("load scroll resize", function() { + var mastheadHeight = 0; + $('#masthead').children().each(function(){mastheadHeight += $(this).height();}); + $('#masthead').css('height',mastheadHeight+'px'); var elem = $('#nav-wrapper'); - if (!elem.attr('data-top')) { - if (elem.hasClass('navbar-fixed-top')) - return; - var offset = elem.offset(); - elem.attr('data-top', offset.top - $('#wpadminbar').outerHeight()); + var thisScroll = $(this).scrollTop(); + if (!elem.hasClass('navbar-fixed-top')){ + var offset = elem.offset(); + var adminHeight = 0; + if($('#wpadminbar').length > 0) adminHeight = $('#wpadminbar').outerHeight(); + elem.attr('data-top', Math.round(parseFloat(offset.top - adminHeight))); } - if (elem.attr('data-top') - elem.outerHeight() <= $(this).scrollTop() - $(elem).outerHeight()){ + if ($(window).width() >= 768 && Math.round(parseFloat(elem.attr('data-top'))) - elem.outerHeight() <= $(this).scrollTop() - $(elem).outerHeight()){ elem.addClass('navbar-fixed-top'); elem.css('padding-top',$('#wpadminbar').outerHeight()); } else { elem.removeClass('navbar-fixed-top'); elem.css('padding-top','0'); - } - - if ($('#nav-wrapper').hasClass('navbar-fixed-top')){ - $('.site-content').css('padding-top' , $('#nav-wrapper').height()); - } - - else { - $('.site-content').css('padding-top' ,'0px'); + $('#masthead').css('height','auto'); } }); $(window).on("resize", function() { + var mastheadHeight = 0; + $('#masthead').children().each(function(){mastheadHeight += $(this).height();}); + $('#masthead').css('height',mastheadHeight+'px'); var elem = $('#nav-wrapper'); - var offset = $('#site-title').offset().top + $('#site-title').outerHeight(); - elem.attr('data-top', offset - $('#wpadminbar').outerHeight()); + if ($(window).width() >= 768 && !elem.hasClass('navbar-fixed-top')){ + var offset = elem.offset(); + var adminHeight = 0; + if($('#wpadminbar').length > 0) adminHeight = $('#wpadminbar').outerHeight(); + elem.attr('data-top', Math.round(parseFloat(offset.top - adminHeight))); + } }); }); \ No newline at end of file