본문 바로가기
홈 · 카테고리 없음

[jQuery] 딤처리 레이어 팝업 여러개 사용

by 도라에몽 2021. 7. 20.
반응형

HTML

<button onclick="openModal('popup1')">첫번째 팝업 열기</button>
<button onclick="openModal('popup2')">두번째 팝업 열기</button>

<div class="popup popup1">
   <a href="#none" class="popup_close">닫기</a>
   <span>첫번째 팝업</span>
</div>
<div class="popup popup2">
   <span>두번째 팝업</span>
</div>

 

CSS

.popup_bg {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .7);
    z-index: 500
}

.btn_popup {
    border: none;
    background: #eee;
    padding: 10px 30px;
    border-radius: 30px
}

.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 200px;
    min-height: 150px;
    background-color: #fff;
    border-radius: 8px;
    z-index: 600;
    transform: translate(-50%, -50%)
}

 

jQuery

function openPopup(popupClass) {
  $("." + popupClass).fadeIn(200);
  $(".popup_bg").fadeIn(200);
}

// 닫기버튼 클릭시
$('.popup_close').click(function() {
  $(this).parent().fadeOut(200);
  $(".popup_bg").fadeOut(200);
});

// 배경 클릭시
$('.popup_bg').click(function() {
  $(this).fadeOut(200);
  $(".popup").fadeOut(200);
});

 

반응형

댓글