zoukankan      html  css  js  c++  java
  • 【Javascript Demo】遮罩层和弹出层简单实现

    最近纠结于遮罩层和弹出层的实现,终于搞定了个简单的版本。示例和代码如下,点击按钮可以看到效果:

    1.示例:

    2.代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
           <head>
                   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     
                  <title>遮罩层和弹出层简单实现</title>
     
                  <script type="text/javascript">
    
                      function show() {
    
                          var div = document.createElement("div");
                          var div_show = document.getElementById("div_show");
                          div.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
                          div.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
                          div.style.backgroundColor = "#000000";
                          div.style.position = "absolute";
                          div.style.opacity = 0.5;
                          div.style.left = 0;
                          div.style.top = 0;
                          div.id = "zhebiceng";
                          div.style.zIndex = 100;
                          top.document.getElementById("div_body").appendChild(div);
    
                          div_show.style.display = "block";
                      }
    
                      function play_show() {
                          var div = top.document.getElementById("zhebiceng");
                          var div_show = document.getElementById("div_show");
                          div_show.style.display = "none";
                          div.style.display = "none";
                          div.parentNode.removeChild(div); 
                      }
                  </script>
     
           </head>
     
           <body>
     
           <div id="div_body">
           <input type="button" value="click" onclick="show()" />
           </div>   
            <div id="div_show" style=" background:white;display: none;height: 400px;left: 80px;  position: fixed;top: 88px;  80%;z-index: 99999;">
           <input type="button" value="关闭" onclick="play_show();" style="float: right;" />
           </div>
           </body>
     
    </html>
  • 相关阅读:
    docker pull 报X509错误
    Kong配置反向代理后获取原始IP
    MybatisPlus框架
    工厂模式
    Mybatis持久层框架
    linux 使用scp传输公钥时要注意事项
    docker 容器容器之间网络通信 docker-compose.yaml 配置固定ip
    Linux下执行sh文件提示权限不够解决办法
    docker-compose 编写yaml文件的注意事项
    nginx 中location url一定要带http://
  • 原文地址:https://www.cnblogs.com/yc-755909659/p/3165275.html
Copyright © 2011-2022 走看看