main.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Template Name: Arsha - v2.0.0
  3. * Template URL: https://bootstrapmade.com/arsha-free-bootstrap-html-template-corporate/
  4. * Author: BootstrapMade.com
  5. * License: https://bootstrapmade.com/license/
  6. */
  7. !(function($) {
  8. "use strict";
  9. // Preloader
  10. $(window).on('load', function() {
  11. if ($('#preloader').length) {
  12. $('#preloader').delay(100).fadeOut('slow', function() {
  13. $(this).remove();
  14. });
  15. }
  16. });
  17. // Smooth scroll for the navigation menu and links with .scrollto classes
  18. $(document).on('click', '.nav-menu a, .mobile-nav a, .scrollto', function(e) {
  19. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  20. var target = $(this.hash);
  21. if (target.length) {
  22. e.preventDefault();
  23. var scrollto = target.offset().top;
  24. var scrolled = 20;
  25. if ($('#header').length) {
  26. scrollto -= $('#header').outerHeight()
  27. if (!$('#header').hasClass('header-scrolled')) {
  28. scrollto += scrolled;
  29. }
  30. }
  31. if ($(this).attr("href") == '#header') {
  32. scrollto = 0;
  33. }
  34. $('html, body').animate({
  35. scrollTop: scrollto
  36. }, 1500, 'easeInOutExpo');
  37. if ($(this).parents('.nav-menu, .mobile-nav').length) {
  38. $('.nav-menu .active, .mobile-nav .active').removeClass('active');
  39. $(this).closest('li').addClass('active');
  40. }
  41. if ($('body').hasClass('mobile-nav-active')) {
  42. $('body').removeClass('mobile-nav-active');
  43. $('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
  44. $('.mobile-nav-overly').fadeOut();
  45. }
  46. return false;
  47. }
  48. }
  49. });
  50. // Mobile Navigation
  51. if ($('.nav-menu').length) {
  52. var $mobile_nav = $('.nav-menu').clone().prop({
  53. class: 'mobile-nav d-lg-none'
  54. });
  55. $('body').append($mobile_nav);
  56. $('body').prepend('<button type="button" class="mobile-nav-toggle d-lg-none"><i class="icofont-navigation-menu"></i></button>');
  57. $('body').append('<div class="mobile-nav-overly"></div>');
  58. $(document).on('click', '.mobile-nav-toggle', function(e) {
  59. $('body').toggleClass('mobile-nav-active');
  60. $('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
  61. $('.mobile-nav-overly').toggle();
  62. });
  63. $(document).on('click', '.mobile-nav .drop-down > a', function(e) {
  64. e.preventDefault();
  65. $(this).next().slideToggle(300);
  66. $(this).parent().toggleClass('active');
  67. });
  68. $(document).click(function(e) {
  69. var container = $(".mobile-nav, .mobile-nav-toggle");
  70. if (!container.is(e.target) && container.has(e.target).length === 0) {
  71. if ($('body').hasClass('mobile-nav-active')) {
  72. $('body').removeClass('mobile-nav-active');
  73. $('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
  74. $('.mobile-nav-overly').fadeOut();
  75. }
  76. }
  77. });
  78. } else if ($(".mobile-nav, .mobile-nav-toggle").length) {
  79. $(".mobile-nav, .mobile-nav-toggle").hide();
  80. }
  81. // Navigation active state on scroll
  82. var nav_sections = $('section');
  83. var main_nav = $('.nav-menu, #mobile-nav');
  84. $(window).on('scroll', function() {
  85. var cur_pos = $(this).scrollTop() + 90;
  86. nav_sections.each(function() {
  87. var top = $(this).offset().top,
  88. bottom = top + $(this).outerHeight();
  89. if (cur_pos >= top && cur_pos <= bottom) {
  90. if (cur_pos <= bottom) {
  91. main_nav.find('li').removeClass('active');
  92. }
  93. main_nav.find('a[href="#' + $(this).attr('id') + '"]').parent('li').addClass('active');
  94. }
  95. if (cur_pos < 300) {
  96. $(".nav-menu ul:first li:first").addClass('active');
  97. }
  98. });
  99. });
  100. // Toggle .header-scrolled class to #header when page is scrolled
  101. $(window).scroll(function() {
  102. if ($(this).scrollTop() > 100) {
  103. $('#header').addClass('header-scrolled');
  104. } else {
  105. $('#header').removeClass('header-scrolled');
  106. }
  107. });
  108. if ($(window).scrollTop() > 100) {
  109. $('#header').addClass('header-scrolled');
  110. }
  111. // Back to top button
  112. $(window).scroll(function() {
  113. if ($(this).scrollTop() > 100) {
  114. $('.back-to-top').fadeIn('slow');
  115. } else {
  116. $('.back-to-top').fadeOut('slow');
  117. }
  118. });
  119. $('.back-to-top').click(function() {
  120. $('html, body').animate({
  121. scrollTop: 0
  122. }, 1500, 'easeInOutExpo');
  123. return false;
  124. });
  125. })(jQuery);