main.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. !(function($) {
  2. "use strict";
  3. // Toggle .header-scrolled class to #header when page is scrolled
  4. $(window).scroll(function() {
  5. if ($(this).scrollTop() > 100) {
  6. $('#header').addClass('header-scrolled');
  7. } else {
  8. $('#header').removeClass('header-scrolled');
  9. }
  10. });
  11. if ($(window).scrollTop() > 100) {
  12. $('#header').addClass('header-scrolled');
  13. }
  14. // Smooth scroll for the navigation menu and links with .scrollto classes
  15. $(document).on('click', '.nav-menu a, .mobile-nav a, .scrollto', function(e) {
  16. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  17. e.preventDefault();
  18. var target = $(this.hash);
  19. if (target.length) {
  20. var scrollto = target.offset().top;
  21. var scrolled = 20;
  22. if ($('#header').length) {
  23. scrollto -= $('#header').outerHeight()
  24. if (!$('#header').hasClass('header-scrolled')) {
  25. scrollto += scrolled;
  26. }
  27. }
  28. if ($(this).attr("href") == '#header') {
  29. scrollto = 0;
  30. }
  31. $('html, body').animate({
  32. scrollTop: scrollto
  33. }, 1500, 'easeInOutExpo');
  34. if ($(this).parents('.nav-menu, .mobile-nav').length) {
  35. $('.nav-menu .active, .mobile-nav .active').removeClass('active');
  36. $(this).closest('li').addClass('active');
  37. }
  38. if ($('body').hasClass('mobile-nav-active')) {
  39. $('body').removeClass('mobile-nav-active');
  40. $('.mobile-nav-toggle i').toggleClass('');
  41. $('.mobile-nav-overly').fadeOut();
  42. }
  43. return false;
  44. }
  45. }
  46. });
  47. /* For Mobile navigation */
  48. $(".mobNav, .close-btn").on('click',function() {
  49. $('.headerMenu').toggleClass('active');
  50. $(this).find('i').toggleClass('fa-times');
  51. });
  52. $(".mobNav-footer, .close-btn2").on('click',function() {
  53. $('.headerMenu-footer').toggleClass('active');
  54. $(this).find('i').toggleClass('fa-times');
  55. });
  56. })(jQuery);