ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [HTML_Tip] 모달 레이어 만들기
    Dev_Tip/HTML_Tip 2021. 8. 4. 16:56
    반응형
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset='UTF-8'>
        <meta name='viewport' content='width=device-width, initial-scale=1.0'>
        <script>
          window.onload = function() {
          
            document.querySelector("#btnViewLaw").addEventListener('click', show);
            document.querySelector("#btnViewclose").addEventListener('click', close);
          
          }
    
          // 미리보기 modal 노출
          function show () {
            document.querySelector(".background").className = "background show";
          }
          
          // 미리보기 modal 숨김
          function close () { 
            document.querySelector(".background").className = "background";
          }
      
        </script>
        <style>
          .background {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100vh;
            background-color: rgba(0, 0, 0, 0.3);
            z-index: 1000;
            
            /* 숨기기 */
            z-index: -1;
            opacity: 0;
          }
    
          .show {
            opacity: 1;
            z-index: 1000;
            transition: all .5s;
          }
    
          .window {
            position: relative;
            width: 100%;
            height: 100%;
          }
    
          .popup {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #ffffff;
            box-shadow: 0 2px 7px rgba(0, 0, 0, 0.3);
            width: 300px;
            height: 300px;
            transform: translate(-50%, -40%);
          }
    
          .show .popup {
            transform: translate(-50%, -50%);
            transition: all .5s;
          }
    
          #popup-title{ margin: 20px 20px 20px 20px; } 
          #popup-contents{ margin: 0px 20px 20px 20px; padding: 10px 10px 10px 10px; height: 55%; border: 1px solid gray; }
    
        </style>
    </head>
    <body style="background-color:gray">
    
      <button type="button" id="btnViewLaw">미리보기</button>
    
      <!-- 미리보기 modal -->
    	<div class="background">
    	  <div class="window">
    	    <div class="popup">
    	    	<div align="right">
    	    		<button type="button" id="btnViewclose">X</button>	
    	    	</div>
    	    	<div id="popup-title">
              모달 제목
    	    	</div>
    	    	<div id="popup-contents">
              모달 내용
    	    	</div>
    	    </div>
    	  <div>
    	<div>
    
    </body>
    </html>
    반응형

    'Dev_Tip > HTML_Tip' 카테고리의 다른 글

    자동완성기능 해제 하기  (0) 2021.04.14
    a태그 링크 비활성화하기  (0) 2021.02.17

    댓글

Designed by Tistory.