└── script.js /script.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | 3 | const isMobile = { 4 | Android: function () { 5 | return navigator.userAgent.match(/Android/i); 6 | }, 7 | BlackBerry: function () { 8 | return navigator.userAgent.match(/BlackBerry/i); 9 | }, 10 | iOS: function () { 11 | return navigator.userAgent.match(/iPhone|iPad|iPod/i); 12 | }, 13 | Opera: function () { 14 | return navigator.userAgent.match(/Opera Mini/i); 15 | }, 16 | Windows: function () { 17 | return navigator.userAgent.match(/IEMobile/i); 18 | }, 19 | any: function () { 20 | return ( 21 | isMobile.Android() || 22 | isMobile.BlackBerry() || 23 | isMobile.iOS() || 24 | isMobile.Opera() || 25 | isMobile.Windows()); 26 | } 27 | }; 28 | 29 | if (isMobile.any()) { 30 | document.body.classList.add('_touch'); 31 | 32 | let menuArrows = document.querySelectorAll('.menu__arrow'); 33 | if (menuArrows.length > 0) { 34 | for (let index = 0; index < menuArrows.length; index++) { 35 | const menuArrow = menuArrows[index]; 36 | menuArrow.addEventListener("click", function (e) { 37 | menuArrow.parentElement.classList.toggle('_active'); 38 | }); 39 | } 40 | } 41 | 42 | } else { 43 | document.body.classList.add('_pc'); 44 | } 45 | 46 | // Меню бургер 47 | const iconMenu = document.querySelector('.menu__icon'); 48 | const menuBody = document.querySelector('.menu__body'); 49 | if (iconMenu) { 50 | iconMenu.addEventListener("click", function (e) { 51 | document.body.classList.toggle('_lock'); 52 | iconMenu.classList.toggle('_active'); 53 | menuBody.classList.toggle('_active'); 54 | }); 55 | } 56 | 57 | 58 | // Прокрутка при клике 59 | const menuLinks = document.querySelectorAll('.menu__link[data-goto]'); 60 | if (menuLinks.length > 0) { 61 | menuLinks.forEach(menuLink => { 62 | menuLink.addEventListener("click", onMenuLinkClick); 63 | }); 64 | 65 | function onMenuLinkClick(e) { 66 | const menuLink = e.target; 67 | if (menuLink.dataset.goto && document.querySelector(menuLink.dataset.goto)) { 68 | const gotoBlock = document.querySelector(menuLink.dataset.goto); 69 | const gotoBlockValue = gotoBlock.getBoundingClientRect().top + pageYOffset - document.querySelector('header').offsetHeight; 70 | 71 | if (iconMenu.classList.contains('_active')) { 72 | document.body.classList.remove('_lock'); 73 | iconMenu.classList.remove('_active'); 74 | menuBody.classList.remove('_active'); 75 | } 76 | 77 | window.scrollTo({ 78 | top: gotoBlockValue, 79 | behavior: "smooth" 80 | }); 81 | e.preventDefault(); 82 | } 83 | } 84 | } --------------------------------------------------------------------------------