(function ($) { /** * Add functions as jQuery callback */ $(document).ready(function () { $('.header-container').ipFixNavbar(); $('#back-to-top').ipBackToTop(); }); /** * Fixed navigation bar * Hide while scrolling down * Show when going up */ $.fn.ipFixNavbar = function () { if (ipTheme.fixedNavbar !== 'fixed') return; var el = this; el.parent().css('min-height', el.innerHeight() + 'px'); $(window).on('resize', function () { el.parent().css('min-height', 0); el.parent().css('min-height', el.innerHeight() + 'px'); }); if (el.hasClass('header-type_logo_center')) { var threshold = 240; } else { var threshold = 96; } var lastTop = $(window).scrollTop(); var isGoingUp = false; $(window).on('scroll', function () { if ($(window).scrollTop() < lastTop) { isGoingUp = true; } else { isGoingUp = false; } lastTop = $(window).scrollTop(); if ($(window).scrollTop() > threshold && !el.hasClass('navigation-fixed') ) { el .addClass('navigation-fixed') .removeClass('navigation-initial'); } if (isGoingUp && !el.hasClass('navigation-fixed')) { el .addClass('navigation-fixed') .removeClass('navigation-initial'); } if (!isGoingUp && el.hasClass('navigation-fixed')) { el .removeClass('navigation-fixed') .addClass('navigation-initial'); } if ($(window).scrollTop() < threshold && el.hasClass('navigation-fixed')) { el .removeClass('navigation-fixed') .removeClass('navigation-initial'); } }); }; /** * Back to top button * Show if scrolled more than 300px */ $.fn.ipBackToTop = function () { if (ipTheme.backToTop !== 'show') return; var el = this; el.on('click', function (e) { e.preventDefault(); $('html').animate({ scrollTop: 0 }, 500); }); $(window).on('scroll', function () { if ($(window).scrollTop() > 300 && !el.hasClass('back-to-top-showing')) { el.addClass('back-to-top-showing'); } if ($(window).scrollTop() < 300 && el.hasClass('back-to-top-showing')) { el.removeClass('back-to-top-showing'); } }); }; })(jQuery);