<button class="button button_primary" type="submit" data-modal-opener>
Open modal
</button>
<div class="modal" id="modal">
<svg class="modal__close" id="modal-close"
fill="none" width="24" height="24">
<use href="/assets/images/svg-sprites.svg#close" />
</svg>
<div class="modal__container modal__container_column">
<div class="inputText">
<label class="inputText__label" for="input1">
Name:
</label>
<div class="inputText__fieldWrapper">
<input
class="inputText__field"
id="input1"
type="text"
placeholder="Placeholder"
/>
</div>
</div>
<div class="inputText">
<label class="inputText__label" for="input1">
Email: </label>
<div class="inputText__fieldWrapper">
<input
class="inputText__field"
id="input1"
type="text"
placeholder="Placeholder"
/>
</div>
</div>
<button class="button button_primary" type="
submit"
>Submit</button>
</div>
</div>
<script>
window.addEventListener('load', () => {
const close = document.getElementById('modal-close');
const modal = document.getElementById('modal');
const modalOpen = document.querySelectorAll('[data-modal-opener]');
if (!close || !modalOpen || !modal) {
console.log('modal init error', close, modal, modalOpen);
return;
}
modalOpen.forEach((item) => {
item.removeAttribute('data-modal-opener');
item.addEventListener('click', () => {
console.log('click');
modal.setAttribute('data-open', false);
document.body.overflow = 'hidden';
});
});
close.addEventListener('click', () => {
modal.removeAttribute('data-open');
document.body.overflow = 'initial';
});
});
</script>
.modal {
opacity: 0;
z-index: 4;
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
background: #c4c4c4;
transform: translateX(-100vw);
transition: opacity 300ms ease-out;
}
.modal__container {
position: relative;
border-radius: 8px;
background: var(--white);
max-width: 428px;
padding: 30px 40px 33px 40px;
}
.modal__title {
margin: 0 0 14px 0;
color: var(--modalTitle);
font-family: Inter;
font-size: 20px;
font-style: normal;
font-weight: 600;
line-height: 24px;
}
.modal__text {
margin: 0px;
color: var(--alternate);
font-family: Inter;
font-size: 16px;
font-style: normal;
font-weight: 400;
line-height: 24px;
}
.modal__close {
position: absolute;
right: 12px;
top: 12px;
transform: rotate(0);
transition: transform 250ms ease-in-out;
}
.modal__close:hover {
transform: rotate(180deg);
}
.modal[data-open] {
opacity: 1;
transform: translateX(0);
}
.modal_preview {
opacity: 1;
transform: translateX(0);
position: relative;
width: 284px;
height: 222px;
background-color: var(--grey-3);
}
.modal_preview .modal__container {
padding: 15px;
transform: scale(0.7);
}
.modal__container_column {
display: flex;
flex-direction: column;
gap: 10px;
}