Skip to content

Commit

Permalink
body fix with open modal
Browse files Browse the repository at this point in the history
  • Loading branch information
IrynaSlavinska committed Apr 26, 2024
1 parent 4d76011 commit fd16e22
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import './js/scroll-up';
refs.closeModalBtn.addEventListener('click', toggleModal);

refs.modal.addEventListener('click', onBackdropClose);

document.body.addEventListener('keydown', onEscClose);

function onBackdropClose(e) {
if (e.currentTarget !== e.target) {
return;
Expand All @@ -39,5 +41,10 @@ import './js/scroll-up';
}
function toggleModal() {
refs.modal.classList.toggle('is-hidden');
if (refs.modal.classList.contains('is-hidden')) {
document.body.style.overflow = 'auto';
} else {
document.body.style.overflow = 'hidden';
}
}
})();

0 comments on commit fd16e22

Please sign in to comment.