弹出层制作

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>弹出层制作</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
  <style>
    body{
      background:#f8f8f8;
    }
    /* 弹出层遮罩 */
    .layer-mask{
      display: none;
      z-index: 99998;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      /* background:#000;
      opacity: 0.5; */
      background:rgba(0, 0, 0, .5)
    }
    /* 弹出层窗体 */
    .layer-pop{
      display: none;
      z-index: 99999;
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: auto;
      width: 400px;
      height: 300px;
      background: #fff;
    }
    /* 弹出层关闭按钮 */
    .layer-close{
      float: right;
      width: 24px;
      height: 24px;
      border: 3px solid #ddd;
      text-align-last: center;
      line-height: 24px;
      border-radius: 50%;
      background: #eee;
      margin-right: -12px;
      margin-top: -12px;
    }
    .layer-close:hover{
      cursor: pointer;
      background: #ccc;
      color: #5082ff;
    }

  </style>
</head>
<body>

  <button  id="loginLink" href="#">登录</button>
    
   <!-- 弹出层遮罩 -->
  <div id="layer-mask" class="layer-mask"> </div>
    <!-- 弹出层窗体 -->
   <div id="layer-pop" class="layer-pop">
     <!-- 弹出层关闭按钮 -->
       <div id="layer-close" class="layer-close">×</div>
       <!-- 弹出层内容区域 -->
       <div id="layer-content" class="layer-content"> 
       </div>
   </div>

   <script>
     $(document).ready(function(){
      $('#loginLink').on('click',function(){ 
        // $('#layer-mask').show()
        // $('#layer-pop').show() 
        $('#layer-mask').show()
        $('#layer-pop').slideDown(500)
     })

     $('#layer-close').on('click',function(){ 
        $('#layer-mask').hide()
        $('#layer-pop').hide() 
     })

     $('#layer-mask').on('click',function(){ 
        $('#layer-mask').hide()
        $('#layer-pop').hide() 
     })
 
      
    }) 
     
   </script>
</body>
</html>
posted @ 2020-08-25 22:00  13522679763-任国强  阅读(116)  评论(0)    收藏  举报