• 【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>
  • 相关阅读:
    SA练习题总结-篇一
    树上距离(树形DP)
    Codeforces Round #633(Div.2) E. Perfect Triples
    Codeforces Round #633 (Div. 2) D.Edge Weight Assignment
    问题 B: FZB(树形DP+边记忆化)
    【Matlab】自学笔记——基础知识篇
    【Python科学计算】Numpy——ndarry
    退役总结
    [树的遍历]树的遍历(PTA)
    [stl]集合相似度(PTA)
  • 原文地址:https://www.cnblogs.com/yc-755909659/p/3165275.html
Copyright © 2020-2023  润新知