inspec/www/source/javascripts/nav.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

// Nav Scripts
const $navLinks = $('.main-nav--links');
const $navToggle = $('.main-nav--toggle');
const navBreakpoint = 730; // this should match $nav-breakpoint in _nav.scss
const $mainContent = $('#main-content');
2016-09-26 20:05:06 +00:00
const $mainNav = $('#main-nav');
$navToggle.click(function() {
$(this).toggleClass('is-active');
$navLinks.slideToggle();
});
$(window).resize(function() {
if ($(window).width() >= navBreakpoint) {
$navToggle.removeClass('is-active');
$navLinks.attr("style", "");
}
});
// toggles fixed nav position when the window is too short
2016-09-29 21:56:09 +00:00
var footerOffsetTop, navOffsetBottom;
function toggleFixedNavPosition() {
2016-09-26 20:05:06 +00:00
navOffsetBottom = $mainNav.outerHeight() + $(window).scrollTop();
2016-09-29 21:56:09 +00:00
footerOffsetTop = $("#main-footer").offset().top;
2016-09-29 21:56:09 +00:00
$mainNav.toggleClass("is-fixed-bottom", (footerOffsetTop < navOffsetBottom) && $(window).height() <= 759)
}
2016-09-29 21:56:09 +00:00
$(document).ready(function() {
$mainContent.css('min-height', $mainNav.outerHeight() - $('#main-nav-ctas').outerHeight());
toggleFixedNavPosition();
});
$(window).scroll(function() {
toggleFixedNavPosition();
});
2016-09-29 21:56:09 +00:00