80tmp.js 3.56 KB
// source --> http://commonwell.test/wp-content/themes/commonwell-corp/scripts/moblie_menu.js?ver=eb276de0ff0635440df790c71d6d729b 
jQuery(document).ready(
    function ($) {


        // Hide Header on on scroll down
        var didScroll;
        var lastScrollTop = 0;
        var delta = 5;
        var navbarHeight = ($('#mainNav').outerHeight() / 2);

        $(window).scroll(
            function (event) {
                didScroll = true;
            }
        );

        setInterval(
            function () {
                if (didScroll) {
                    hasScrolled();
                    didScroll = false;
                }
            }, 250
        );

        function hasScrolled() {
            var st = $(this).scrollTop();

            // Make sure they scroll more than delta
            if (Math.abs(lastScrollTop - st) <= delta)
                return;
            //console.log($(location).attr('pathname'));
            // If they scrolled down and are past the navbar, add class .nav-up.
            // This is necessary so you never see what is "behind" the navbar.
            if (st > lastScrollTop && st > navbarHeight) {
                // Scroll Down

                if ($(location).attr('pathname') == '/broker-landing-page/') {
                    $('#mainNav').removeClass('landing-nav-down').addClass('landing-nav-up');
                } else {
                    $('#mainNav').removeClass('nav-down').addClass('nav-up');
                }

                $('#content-wrap').removeClass('wrap-down').addClass('wrap-up');
            } else {
                // Scroll Up
                if (st + $(window).height() < $(document).height()) {

                    if ($(location).attr('pathname') == '/broker-landing-page/') {
                        $('#mainNav').removeClass('landing-nav-up').addClass('landing-nav-down');
                    } else {

                        $('#mainNav').removeClass('nav-up').addClass('nav-down');
                    }

                    $('#content-wrap').removeClass('wrap-up').addClass('wrap-down');

                }
            }

            lastScrollTop = st;
        }

        var $menu = $('#mySidenav');

        $(document).mouseup(function (e) {
           if ($(e.target).is('#mobile-menu-btn')){
                $('.menu-item-has-children').removeClass('open-menu');
                $("#mySidenav").toggleClass('mobile-open');
           } else {
            if($(e.target).parents('#mySidenav').length == 0) {
                $('.menu-item-has-children').removeClass('open-menu');     
                $("#mySidenav").removeClass('mobile-open');  
            }
           }
        });
         
          if(window.location.hash && jQuery('#quiz').length > 0) {

            $('html, body').animate({scrollTop:0});
            
            var elm = window.location.hash.replace('#', '');
                elm = document.getElementById(elm);

            setTimeout(function() {
                $('html, body').stop().animate({   scrollTop: elm.offsetTop + 10  }, 900, 'linear');
            }, 240);
              
                 
         }
          



   


    });

    // function openNav(e) {
    //     jQuery("#mySidenav").removeClass('mobile-close');
    //     jQuery("#mySidenav").addClass('mobile-open');
    //   }
      
      /* Set the width of the side navigation to 0 and the left margin of the page content to 0, and the background color of body to white */
    //   function closeNav() {
    //     jQuery("#mySidenav").removeClass('mobile-open');
    //     jQuery("#mySidenav").addClass('mobile-close');
    //   };