class Modal { constructor( modalId, triggerElement ) { this.modal = document.getElementById( modalId ); if ( this.modal ) { this.triggerElement = document.querySelector( triggerElement ); this.triggerElement.addEventListener( 'click', () => this.openModal() ); window.addEventListener( 'click', ( event ) => { if ( event.target === this.modal ) { this.closeModal(); } } ); } } openModal() { this.modal.style.zIndex = '100'; this.modal.style.opacity = '1'; this.modal.style.visibility = 'visible'; } closeModal() { this.modal.style.zIndex = '-100'; this.modal.style.opacity = '0'; this.modal.style.visibility = 'hidden'; } } new Modal( 'login-modal', 'a[href="#login"]' ); new Modal( 'estimate-modal', 'a[href="#estimate"]' );