Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed stickynav bug
  • Loading branch information
Roy committed Jan 18, 2017
1 parent 83bdb4b commit b204c20
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions 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)));
}
});
});

0 comments on commit b204c20

Please sign in to comment.