Skip to content

Commit

Permalink
Merge pull request #129 from Kumiho1/feature/popup-slider
Browse files Browse the repository at this point in the history
refactor: закрытие по esc и оверфлоу
  • Loading branch information
sofiapeshekhonova authored Oct 28, 2022
2 parents a35af66 + b91aa72 commit 2fbcd05
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fillPopup();
galleryPhoto.forEach( item => {
item.addEventListener('click', () => {
openPopup(galleryPopup);
document.addEventListener("keydown", closeOnButtonEscape);
})
})

Expand All @@ -37,9 +38,22 @@ function fillPopup() {
});
}


console.log()
closePopup.addEventListener('click', evt => {
popupClose(galleryPopup);
document.removeEventListener("keydown", closeOnButtonEscape);
});


function closeOnButtonEscape(evt) {
if (evt.key === "Escape") {
const popupOpened = document.querySelector(".popup_opened");
popupClose(popupOpened);
}
}

galleryPopup.addEventListener("mousedown", (evt) => {
if (evt.target.classList.contains("popup_opened")) {
popupClose(galleryPopup);
}
});

0 comments on commit 2fbcd05

Please sign in to comment.