zoukankan      html  css  js  c++  java
  • 点击弹出居中带有透明遮罩层窗口

    代码如下:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=" utf-8">
    <meta name="author" content="http://www.softwhy.com/" />
    <title>蚂蚁部落</title>
    <style type="text/css">
    #fade {
      display:none;
      position:absolute;
      top:0%;
      left:0%;
      100%;
      height:100%;
      background-color:black;
      z-index:1001;
      -moz-opacity:0.8;
      opacity:.80;
      filter:alpha(opacity=80);
    }
    #light{
      display:none;
      position:absolute;
      top:25%;
      left:25%;
      50%;
      height:50%;
      padding:16px;
      border:3px solid orange;
      background-color:white;
      z-index:1002;
      overflow:auto;
    }
    </style>
    <script type="text/javascript">
    window.onload=function(){
       var linkbt=document.getElementById("linkbt");
       var light=document.getElementById('light');
       var fade=document.getElementById('fade');
       var closebt=document.getElementById("closebt");
       linkbt.onclick=function(){
         light.style.display='block';
         fade.style.display='block';
       }
       closebt.onclick=function(){
         light.style.display='none';
         fade.style.display='none';
       }
    }
    </script>
    </head>
    <body>
    <a href="javascript:void(0)" id="linkbt"> 点击这里打开窗口</a>
    <div id="light"><a href="javascript:void(0)" id="closebt">关闭窗口</a></div>
    <div id="fade""></div>
    </body>
    </html>

    一.实现原理:
    在 默认状态下,遮罩层和窗口都是隐藏不可见的,当点击链接之后,能够使窗口和遮罩层显示,并且将遮罩层设置为半透明状态。此两个元素都采用绝对定位同时设置 居中窗口的z-index属性值大于遮罩层,这样就可以使其覆盖在遮罩层之上。当点击关闭按钮的时候,能够将遮罩层和窗口隐藏,原理大致如此。
     

    后来都会美好的!
  • 相关阅读:
    HTML5结构
    HTML5新增的非主体元素header元素、footer元素、hgroup元素、adress元素
    CF GYM 100703G Game of numbers
    CF GYM 100703I Endeavor for perfection
    CF GYM 100703K Word order
    CF GYM 100703L Many questions
    CF GYM 100703M It's complicate
    HDU 5313 Bipartite Graph
    CF 560e Gerald and Giant Chess
    POJ 2479 Maximum sum
  • 原文地址:https://www.cnblogs.com/momox/p/5090798.html
Copyright © 2011-2022 走看看