@zver28
Просто пыль

Как закрывать модальное окно, по клику в пустую область?

есть модальное окно вида:

<!-- Модальное окно 1 -->
<div id="mod">
<aside id="example" class="modalius">
<div>
<h2 >Дополнительная информация:</h2>
<ul>
<li>Время работы мастеров: с 10:00 до 20:00</li>
<li>Время работы Call-Центра: с 10:00 до 21:00</li>
<li>Рабочие дни: Ежедневно, кроме праздников</li><br>
<li>Телефоны: 00-00-00 или 00-00-00</li>
<li>Доп.телефон: +7 000-000-00-00</li>
<li>Доп.телефон: +7 000-000-00-00</li><br>
</ul>
<a class="x" data-close="attr" href="<?php echo $modalius_close; ?>" title="Закрыть">Закрыть</a>
</div>
</aside>
<div>
<!-- Модальное окно 1 -->


Вызываю я его так:

<a href="htpp://site.ru/page1/#example" title="Нажмите для ознакомления.">Нажать</a>


его css:

/* Контейнер */
.modalius {

/* Слой перекрытия */
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 9999;



/* Трансформации прозрачности при открытии  */
-webkit-transition: opacity 500ms ease-in;
-moz-transition: opacity 500ms ease-in;
transition: opacity 500ms ease-in;

/* Скрываем изначально */
opacity: 0;
pointer-events: none;
}

/* Показываем модальное окно */
.modalius:target {
opacity: 1;
pointer-events: auto;
}

/* Содержание */
.modalius > div {
width: 450px;
background: #fff;
position: relative;
margin: 7% auto;

/* По умолчанию минимизируем анимацию */
-webkit-animation: minimise 500ms linear;

/* Придаем хороший вид */
padding: 30px;
padding-bottom:10px;
-moz-border-radius: 7px;
border-radius: 7px;
-webkit-box-shadow: 0 3px 20px rgba(0,0,0,0.9);
-moz-box-shadow: 0 3px 20px rgba(0,0,0,0.9);
box-shadow: 0 3px 20px rgba(0,0,0,0.9);
background: -moz-linear-gradient(#fff, #ccc);
background: -webkit-gradient(linear, right bottom, right top, color-stop(1, rgb(255,255,255)), color-stop(0.57, rgb(230,230,230)));
/* text-shadow: 0 1px 0 #fff; */

font-family: 'Roboto-Regular';
font-size: 17px;
text-align: center;
}

/* Изменяем анимацию при открытии модального окна*/
.modalius:target > div {
-webkit-animation-name: bounce;
}

.modalius h2 {
	
	font-family: 'Roboto-Bold';
	
font-size: 25px;
padding: 0 0 0px;
text-align: center;
margin-top: 0px;
}

@-webkit-keyframes bounce {
  0% {
  	-webkit-transform: scale3d(0.1,0.1,1);
  	-webkit-box-shadow: 0 3px 20px rgba(0,0,0,0.9);
  }
  55% {
  	-webkit-transform: scale3d(1.08,1.08,1);
  	-webkit-box-shadow: 0 10px 20px rgba(0,0,0,0);
  }
  75% {
  	-webkit-transform: scale3d(0.95,0.95,1);
  	-webkit-box-shadow: 0 0 20px rgba(0,0,0,0.9);
  }
  100% {
  	-webkit-transform: scale3d(1,1,1);
  	-webkit-box-shadow: 0 3px 20px rgba(0,0,0,0.9);
  }
}

@-webkit-keyframes minimise {
  0% {
  	-webkit-transform: scale3d(1,1,1);
  }
  100% {
  	-webkit-transform: scale3d(0.1,0.1,1);
  }
}

/* Ссылка на кнопку Закрыть */
.modalius a[data-close="attr"] {
position: absolute;
right: 0;
top: 0;
color: transparent;
}

/* Сбрасываем изменения */
.modalius a[data-close="attr"]:focus {
outline: none;
}

/* Создаем кнопку Закрыть */
.modalius a[data-close="attr"]:after {
content: 'X';
display: block;

/* Позиционируем */
position: absolute;
right: -10px;
top: -10px;
width: 1.5em;
padding: 1px 1px 1px 2px;

/* Стили */
text-decoration: none;
text-shadow: none;
text-align: center;
font-weight: bold;
background: #000;
color: #fff;
border: 3px solid #fff;
-moz-border-radius: 20px;
border-radius: 20px;
-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.5);
-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.5);
box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.modalius a[data-close="attr"]:focus:after,
.modalius a[data-close="attr"]:hover:after {
-webkit-transform: scale(1.1,1.1);
-moz-transform: scale(1.1,1.1);
}

.modalius a[data-close="attr"]:focus:after {
outline: 1px solid #000;
}

/* Открываем модальное окно */
a.openmodalius {
margin: 1em auto;
display: block;
width: 200px;
background: #ccc;
text-align: center;
padding: 10px;
-moz-border-radius: 7px;
border-radius: 7px;
background: -moz-linear-gradient(#fff, #ddd);
background: -webkit-gradient(linear, right top, right bottom, from(rgb(255,255,255)), to(rgb(230,230,230)));
text-shadow: 0 1px 0 #fff;
border: 1px solid rgba(0,0,0,0.1);
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.3);
-moz-box-shadow: 0 1px 1px rgba(0,0,0,0.3);
box-shadow: 0 1px 1px rgba(0,0,0,0.3);
}

a.openmodalius:hover,
a.openmodalius:focus {
background: -moz-linear-gradient(#fff, #ccc);
background: -webkit-gradient(linear, right top, right bottom, from(rgb(255,255,255)), to(rgb(200,200,200)));
}


На мобильниках оно не вмешается, да и к тому же кроме как на X не закрывается. Хочу что бы в пустую область можно было щелкнуть и он закрылось будто нажали на X

Этот javascript решает проблему НО:

<script type="text/javascript">
$(".modalius").click(function(e) { 

    if($(e.target).closest(".cla").length==0) $(".modalius").css("display","none");

  });
</script>


потом второй раз вызвать его по выше переведенной ссылке не получается, т.к. скрип воткнул значение display","none и все, пока ст. не перегрузишь, не чего не будет, по ссылке модальное окно не вызвать. Помогите решить. Спасибо....
  • Вопрос задан
  • 1227 просмотров
Пригласить эксперта
Ответы на вопрос 3
Exploding
@Exploding
wtf?
$(document).on("click", function(e) { 
if(!$(e.target).closest(".modalius").length) 
   $(".modalius").hide();
   //Или
   //$(".modalius").remove();
  });

Вопрос ниасилил
Ответ написан
webbuddu
@webbuddu
Начинающий.
А так не работает .length) return;
Ответ написан
Комментировать
@maxsnw
так ты делай лучше toggle для класса с display: none; он будет добавлять если его нет и убирать если он есть :)
Ответ написан
Ваш ответ на вопрос

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

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