Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Клик по всплывающем окну закрывает подложку (https://javascript.ru/forum/dom-window/71297-klik-po-vsplyvayushhem-oknu-zakryvaet-podlozhku.html)

chellas88 08.11.2017 15:47

Клик по всплывающем окну закрывает подложку
 
Всем привет. Следующая проблемка. Есть всплывающее окно и под ним оверлей. При клике на оверлей он исчезает, а получается так что при клике на всплывающее окно оверлей также закрывается, хотя не должен.

<div class="black">
		<div class="popup"></div>
	</div>


.black {
	position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: #000000ad;
    z-index: 10;
	display: none;
	cursor: pointer;
}
.popup {
	position: absolute;
    background: #fff;
    top: 20%;
    left: 0;
    right: 0;
    width: 40%;
    margin: auto;
    z-index: 99;
    cursor: default;
}



$('.black').click(function(){
		$(this).hide();
	});
	
	
	$('#add_akt').click(function(){
		$('.black').fadeIn(400, function(){
			$('.popup').show();
			$('.main_menu').hide();
			$('.popup').load('add_akt.php');
		});
		
		
	});

laimas 08.11.2017 16:07

Опять глюки с форумом.

Цитата:

Сообщение от chellas88
$('.black').click(function(){
        $(this).hide();
    });


chellas88 08.11.2017 16:13

Цитата:

Сообщение от laimas (Сообщение 469561)
Опять глюки с форумом.

но нужно чтоб при нажатии на подложку попап закрывался, но не при нажатии на самом попапе

рони 08.11.2017 16:25

chellas88,
$('.popup').click(function(event){
     event.stopPropagation()
    });

рони 08.11.2017 16:28

chellas88,
или так
$('.black').click(function(event){
     $(event.target).closest('.popup').length || $(this).hide();
    });

chellas88 08.11.2017 16:31

Спасибо большое

laimas 08.11.2017 16:32

:) глюки не к теме, а к форуму.

$('.black').click(function(e){
       if(e.target.className=='black') $(this).hide();
    });


Часовой пояс GMT +3, время: 09:48.