Skip to content

Commit

Permalink
Merge pull request #28 from gudzsv/modal-window-js-
Browse files Browse the repository at this point in the history
Modal window js
  • Loading branch information
gudzsv authored Apr 29, 2024
2 parents d7eb588 + 5cd4b52 commit a04b173
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/partials/modal/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity 250ms cubic-bezier(0.4, 0, 0.2, 1),
visibility 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.backdrop.is-open {
opacity: 1;
Expand Down
2 changes: 1 addition & 1 deletion src/partials/modal/modal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="backdrop">
<div class="modal-window">
<button modal="window-btn">
<button modal="button" class="window-btn">
<svg class="window-dtn-icon" width="22" height="22">
<use href="./assets/svg/icons.svg#icon-x"></use>
</svg>
Expand Down
22 changes: 22 additions & 0 deletions src/partials/modal/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const btnClose = document.querySelector('.window-btn');
const windowBackdrop = document.querySelector('.backdrop');

btnClose.addEventListener('click', () => {
closeWindow();
});

windowBackdrop.addEventListener('click', event => {
if (event.target === windowBackdrop) {
closeWindow();
}
});

document.addEventListener('keydown', event => {
if (event.key === 'Escape') {
closeWindow();
}
});

function closeWindow() {
windowBackdrop.classList.remove('is-open');
}

0 comments on commit a04b173

Please sign in to comment.