@mastaJoe

Как сделать так что бы модально окно открывалось при нажатии на обе кнопки?

Работает только одна кнопка, а можно как то сделать что бы работало просто по нажатию на любую кнопку?

var modal = document.getElementById("modalWindow");
var btn = document.getElementById("modalBtn");
var span = document.getElementsByClassName("modal__close")[0];
btn.onclick = function() {
  modal.style.display = "block";
}
span.onclick = function() {
  modal.style.display = "none";
}
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}


<div class="modal-trigger">
		<div class="button">
			<button id="modalBtn" class="button__active"><?php the_field( 'program_btn' ); ?></button>
		</div>
	</div>
	<div class="modal-trigger">
		<div class="button">
			<button id="modalBtn" class="button__active"><?php the_field( 'program_btn' ); ?></button>
		</div>
	</div>


/* modal */
.modal {
	display: none;
	position: fixed;
	z-index: 9;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	overflow: auto;
	background-color: rgb(0,0,0);
	background-color: rgba(0,0,0,0.4);
}
.modal__container {
    position: relative;
    max-width: 400px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0 auto;
    padding: 15px 20px 20px;
    border-radius: 14px;
    background-color: #F9F4F0;
	z-index: 11;
}
.modal__header {
    margin-bottom: 20px;
}
.modal__title {
    font-weight: 500;
}
.modal__close {
    position: absolute;
    top: 7px;
    right: 13px;
    border: none;
    outline: none;
    font-size: 24px;
    font-weight: bold;
	background: none;
    color: #747474;
	cursor: pointer;
}
.modal__close:hover {
	color: #000;
}
.modal-trigger {
	display: flex;
	justify-content: center;
	padding-top: 20px;
}
.button {
	position: relative;
	display: inline-block;
}
.button:after {
	content: '';
	position: absolute;
	top: 5px;
	left: 0;
	right: 0;
	bottom: 0;
	border-radius: 14px;
	background-color: #aa653c;
	z-index: -1;
}
.button__active {
	display: inline-block;
	margin-bottom: 5px;
    padding: 10px 25px;
    border: 1px solid $main-color;
    border-radius: 14px;
    font-size: 14px;
    text-transform: uppercase;
	-webkit-transition: all 0.5s;
	transition: all 0.5s;
    background-color: #dc834e;
    color: #F9F4F0;
    outline: none;
    cursor: pointer;
}
.button__active:hover {
  -webkit-transform: translateY(5px);
  transform: translateY(5px);
}
  • Вопрос задан
  • 61 просмотр
Пригласить эксперта
Ответы на вопрос 1
SemanticMoscow
@SemanticMoscow
оффтоп: а не многовато ли кода для простого модального окна?
<style>div{display:none}</style>
<button data-m="modal" onclick="document.getElementById(this.dataset.m).style.display='block'">покажись</button><div id="modal">я окно</div>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы