/* JS Document */ /****************************** [Table of Contents] 1. Vars and Inits 2. Set Header 3. Init Menu 4. Init Accordions ******************************/ $(document).ready(function() { "use strict"; /* 1. Vars and Inits */ var header = $('.header'); var menu = $('.menu'); var menuActive = false; var hamb = $('.hamburger'); setHeader(); $(window).on('resize', function() { setHeader(); setTimeout(function() { $(window).trigger('resize.px.parallax'); }, 375); }); $(document).on('scroll', function() { setHeader(); }); initMenu(); initAccordions(); /* 2. Set Header */ function setHeader() { if($(window).scrollTop() > 91) { header.addClass('scrolled'); } else { header.removeClass('scrolled'); } } /* 3. Init Menu */ function initMenu() { if($('.hamburger').length && $('.menu').length) { hamb.on('click', function() { if(!menuActive) { openMenu(); } else { closeMenu(); } }); } } function openMenu() { menu.addClass('active'); hamb.addClass('active'); menuActive = true; } function closeMenu() { menu.removeClass('active'); hamb.removeClass('active'); menuActive = false; } /* 4. Init Accordions */ function initAccordions() { if($('.accordion').length) { var accs = $('.accordion'); accs.each(function() { var acc = $(this); if(acc.hasClass('active')) { var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } } acc.on('click', function() { if(acc.hasClass('active')) { acc.removeClass('active'); var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } setTimeout(function() { $(window).trigger('resize.px.parallax'); }, 500); } else { acc.addClass('active'); var panel = $(acc.next()); var panelH = panel.prop('scrollHeight') + "px"; if(panel.css('max-height') == "0px") { panel.css('max-height', panel.prop('scrollHeight') + "px"); } else { panel.css('max-height', "0px"); } setTimeout(function() { $(window).trigger('resize.px.parallax'); }, 500); } }); }); } } });