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

Fixed stickynav bug #150

Merged
merged 2 commits into from Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.innerWidth >= 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.innerWidth >= 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)));
}
});
});