Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Template Name: iLanding
  3. * Template URL: https://bootstrapmade.com/ilanding-bootstrap-landing-page-template/
  4. * Updated: Nov 12 2024 with Bootstrap v5.3.3
  5. * Author: BootstrapMade.com
  6. * License: https://bootstrapmade.com/license/
  7. */
  8. (function() {
  9. "use strict";
  10. /**
  11. * Apply .scrolled class to the body as the page is scrolled down
  12. */
  13. function toggleScrolled() {
  14. const selectBody = document.querySelector('body');
  15. const selectHeader = document.querySelector('#header');
  16. if (!selectHeader.classList.contains('scroll-up-sticky') && !selectHeader.classList.contains('sticky-top') && !selectHeader.classList.contains('fixed-top')) return;
  17. window.scrollY > 100 ? selectBody.classList.add('scrolled') : selectBody.classList.remove('scrolled');
  18. }
  19. document.addEventListener('scroll', toggleScrolled);
  20. window.addEventListener('load', toggleScrolled);
  21. /**
  22. * Mobile nav toggle
  23. */
  24. const mobileNavToggleBtn = document.querySelector('.mobile-nav-toggle');
  25. function mobileNavToogle() {
  26. document.querySelector('body').classList.toggle('mobile-nav-active');
  27. mobileNavToggleBtn.classList.toggle('bi-list');
  28. mobileNavToggleBtn.classList.toggle('bi-x');
  29. }
  30. if (mobileNavToggleBtn) {
  31. mobileNavToggleBtn.addEventListener('click', mobileNavToogle);
  32. }
  33. /**
  34. * Hide mobile nav on same-page/hash links
  35. */
  36. document.querySelectorAll('#navmenu a').forEach(navmenu => {
  37. navmenu.addEventListener('click', () => {
  38. if (document.querySelector('.mobile-nav-active')) {
  39. mobileNavToogle();
  40. }
  41. });
  42. });
  43. /**
  44. * Toggle mobile nav dropdowns
  45. */
  46. document.querySelectorAll('.navmenu .toggle-dropdown').forEach(navmenu => {
  47. navmenu.addEventListener('click', function(e) {
  48. e.preventDefault();
  49. this.parentNode.classList.toggle('active');
  50. this.parentNode.nextElementSibling.classList.toggle('dropdown-active');
  51. e.stopImmediatePropagation();
  52. });
  53. });
  54. /**
  55. * Scroll top button
  56. */
  57. let scrollTop = document.querySelector('.scroll-top');
  58. function toggleScrollTop() {
  59. if (scrollTop) {
  60. window.scrollY > 100 ? scrollTop.classList.add('active') : scrollTop.classList.remove('active');
  61. }
  62. }
  63. scrollTop.addEventListener('click', (e) => {
  64. e.preventDefault();
  65. window.scrollTo({
  66. top: 0,
  67. behavior: 'smooth'
  68. });
  69. });
  70. window.addEventListener('load', toggleScrollTop);
  71. document.addEventListener('scroll', toggleScrollTop);
  72. /**
  73. * Animation on scroll function and init
  74. */
  75. function aosInit() {
  76. AOS.init({
  77. duration: 600,
  78. easing: 'ease-in-out',
  79. once: true,
  80. mirror: false
  81. });
  82. }
  83. window.addEventListener('load', aosInit);
  84. /**
  85. * Initiate glightbox
  86. */
  87. const glightbox = GLightbox({
  88. selector: '.glightbox'
  89. });
  90. /**
  91. * Init swiper sliders
  92. */
  93. function initSwiper() {
  94. document.querySelectorAll(".init-swiper").forEach(function(swiperElement) {
  95. let config = JSON.parse(
  96. swiperElement.querySelector(".swiper-config").innerHTML.trim()
  97. );
  98. if (swiperElement.classList.contains("swiper-tab")) {
  99. initSwiperWithCustomPagination(swiperElement, config);
  100. } else {
  101. new Swiper(swiperElement, config);
  102. }
  103. });
  104. }
  105. window.addEventListener("load", initSwiper);
  106. /**
  107. * Initiate Pure Counter
  108. */
  109. new PureCounter();
  110. /**
  111. * Frequently Asked Questions Toggle
  112. */
  113. document.querySelectorAll('.faq-item h3, .faq-item .faq-toggle').forEach((faqItem) => {
  114. faqItem.addEventListener('click', () => {
  115. faqItem.parentNode.classList.toggle('faq-active');
  116. });
  117. });
  118. /**
  119. * Correct scrolling position upon page load for URLs containing hash links.
  120. */
  121. window.addEventListener('load', function(e) {
  122. if (window.location.hash) {
  123. if (document.querySelector(window.location.hash)) {
  124. setTimeout(() => {
  125. let section = document.querySelector(window.location.hash);
  126. let scrollMarginTop = getComputedStyle(section).scrollMarginTop;
  127. window.scrollTo({
  128. top: section.offsetTop - parseInt(scrollMarginTop),
  129. behavior: 'smooth'
  130. });
  131. }, 100);
  132. }
  133. }
  134. });
  135. /**
  136. * Navmenu Scrollspy
  137. */
  138. let navmenulinks = document.querySelectorAll('.navmenu a');
  139. function navmenuScrollspy() {
  140. navmenulinks.forEach(navmenulink => {
  141. if (!navmenulink.hash) return;
  142. let section = document.querySelector(navmenulink.hash);
  143. if (!section) return;
  144. let position = window.scrollY + 200;
  145. if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) {
  146. document.querySelectorAll('.navmenu a.active').forEach(link => link.classList.remove('active'));
  147. navmenulink.classList.add('active');
  148. } else {
  149. navmenulink.classList.remove('active');
  150. }
  151. })
  152. }
  153. window.addEventListener('load', navmenuScrollspy);
  154. document.addEventListener('scroll', navmenuScrollspy);
  155. })();