window.addEventListener('load', function () { const preloader = document.querySelector('#preloader') preloader.classList.add('hidden') setTimeout(function () { preloader.remove() }, 500) }) document.addEventListener('DOMContentLoaded', function () { let modalBg = document.querySelector('#modal__bg') if (modalBg) { let modalBtnAll = document.querySelectorAll('.modal__btn') let modalBtnCloseAll = document.querySelectorAll('.modal__close') for (const modalBtnItem of modalBtnAll) { modalBtnItem.addEventListener('click', function (e) { e.preventDefault() let modalBtnData = this.dataset.modal let modalSection = document.querySelector( 'section.modal[data-id=' + modalBtnData + ']' ) modalBg.classList.add('opened') modalSection.classList.add('opened') }) } modalBg.addEventListener('click', function () { modalBg.classList.remove('opened') document.querySelector('section.modal.opened').classList.remove('opened') }) for (const modalBtnCloseItem of modalBtnCloseAll) { modalBtnCloseItem.addEventListener('click', function () { modalBg.classList.remove('opened') document .querySelector('section.modal.opened') .classList.remove('opened') }) } } })