/*----------------------------------------------------------- * Template Name : Multirent - Multipurpose / Equipment Rental Website * Author : KreativDev * File Description : This file contains the javaScript functions for the actual template, this is the file you need to edit to change the functionality of the template. *------------------------------------------------------------ */ !(function($) { "use strict"; /*============================================ Mobile menu ============================================*/ var mobileMenu = function() { // Variables var body = $("body"), mainNavbar = $(".main-navbar"), mobileNavbar = $(".mobile-menu"), cloneInto = $(".mobile-menu-wrapper"), cloneItem = $(".mobile-item"), menuToggler = $(".menu-toggler"), offCanvasMenu = $("#offcanvasMenu"), backdrop, _initializeBackDrop = function() { backdrop = document.createElement('div'); backdrop.className = 'menu-backdrop'; backdrop.onclick = function hideOffCanvas() { menuToggler.removeClass("active"), body.removeClass("mobile-menu-active"), backdrop.remove(); }; document.body.appendChild(backdrop); }; menuToggler.on("click", function() { $(this).toggleClass("active"); body.toggleClass("mobile-menu-active"); _initializeBackDrop(); if (!body.hasClass("mobile-menu-active")) { $('.menu-backdrop').remove(); } }) mainNavbar.find(cloneItem).clone(!0).appendTo(cloneInto); if (offCanvasMenu) { body.find(offCanvasMenu).clone(!0).appendTo(cloneInto); } mobileNavbar.find("li").each(function(index) { var toggleBtn = $(this).children(".toggle") toggleBtn.on("click", function(e) { $(this) .parent("li") .children("ul") .stop(true, true) .slideToggle(350); $(this).parent("li").toggleClass("show"); }) }) // check browser width in real-time var checkBreakpoint = function() { var winWidth = window.innerWidth; if (winWidth <= 1199) { mainNavbar.hide(); mobileNavbar.show() } else { mainNavbar.show(); mobileNavbar.hide(); $('.menu-backdrop').remove(); } } checkBreakpoint(); $(window).on('resize', function() { checkBreakpoint(); }); } mobileMenu(); var getHeaderHeight = function() { var headerNext = $(".header-next"); var header = headerNext.prev(".header-area"); var headerHeight = header.height(); headerNext.css({ "margin-top": headerHeight }) } getHeaderHeight(); $(window).on('resize', function() { getHeaderHeight(); }); /*============================================ Navlink active class ============================================*/ // var a = $("#mainMenu .nav-link"), // c = window.location; // for (var i = 0; i < a.length; i++) { // const el = a[i]; // if (el.href == c) { // el.classList.add("active"); // } // } /*============================================ Sticky header ============================================*/ $(window).on("scroll", function() { var header = $(".header-area"); // If window scroll down .is-sticky class will added to header if ($(window).scrollTop() >= 100) { header.addClass("is-sticky"); } else { header.removeClass("is-sticky"); } }); /*============================================ Image to background image ============================================*/ var bgImage = $(".bg-img") bgImage.each(function() { var el = $(this), src = el.attr("data-bg-img"); el.css({ "background-image": "url(" + src + ")", "background-repeat": "no-repeat" }); }); /*============================================ Go to top ============================================*/ $(window).on("scroll", function() { // If window scroll down .active class will added to go-top var goTop = $(".go-top"); if ($(window).scrollTop() >= 200) { goTop.addClass("active"); } else { goTop.removeClass("active") } }) $(".go-top").on("click", function(e) { $("html, body").animate({ scrollTop: 0, }, 0); }); /*============================================ Lazyload image ============================================*/ var lazyLoad = function() { window.lazySizesConfig = window.lazySizesConfig || {}; window.lazySizesConfig.loadMode = 2; lazySizesConfig.preloadAfterLoad = true; } /*============================================ Nice select ============================================*/ $(".niceselect").niceSelect(); var selectList = $(".nice-select .list") $(".nice-select .list").each(function() { var list = $(this).children(); if (list.length > 5) { $(this).css({ "height": "160px", "overflow-y": "scroll" }) } }) /*============================================ Footer date ============================================*/ var date = new Date().getFullYear(); $("#footerDate").text(date); /*============================================ Document on ready ============================================*/ $(document).ready(function() { lazyLoad() }) })(jQuery); $(window).on("load", function() { const delay = 350; /*============================================ Preloader ============================================*/ $("#preLoader").delay(delay).fadeOut('slow'); })