zoukankan      html  css  js  c++  java
  • 弹出层

    *{
                    margin: 0px;
                    padding: 0px;
                }
                .mask{
                     100%;
                    /*height: 500px;*/
                    background-color: gray;
                    opacity: 0.5;
                    z-index: 998;
                    position: absolute;
                    top: 0px;
                    left: 0px;
                }
                .login{
                     400px;
                    height: 300px;
                    background-color: royalblue;
                    position: fixed;
                    /*left: 200px;
                    top: 300px;*/
                    z-index: 999;
                }
                .close-btn{
                     30px;
                    height: 30px;
                    position: absolute;
                    right: 10px;
                    top: 10px;
                    background-color: aquamarine;
                    text-align: center;
                    line-height: 30px;
                    font-size: 30px;
                }
                .close-btn:hover{
                    cursor: pointer;
                }
            </style>
        </head>
    
        <body>
            <input type="button" value="登录" id="login" />
            <script>
                document.getElementById("login").onclick = function(){
                    var x = "<div class='close-btn'>X</div>";
                    showLogin(x);
                }
            </script>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
            <!--<div class="mask"></div>-->
            <!--<div class="login">
                <div class="close-btn">X</div>
            </div>-->
        </body>
    
    </html>
    <script>
        function showLogin(x){
            var bodyHeight = document.body.clientHeight;
            var clientHeight = document.documentElement.clientHeight;
            var clientWidth = document.documentElement.clientWidth;
            
            var mask = document.createElement("div");
            mask.className = "mask";
            mask.style.height = bodyHeight + "px";
            mask.onclick = function(){
                mask.remove();
                login.remove();
                };
            document.body.appendChild(mask);
            
            var login = document.createElement("div");
            login.className = "login";
            login.style.left = clientWidth/2 - 200 + "px";
            login.style.top = clientHeight/2 - 150 + "px";
            login.innerHTML = x;
            document.body.appendChild(login);
            
            document.getElementsByClassName("close-btn")[0].onclick = function(){
                mask.remove();
                login.remove();
            }
        }
        document.body.onresize = function(){
            var clientHeight = document.documentElement.clientHeight;
            var clientWidth = document.documentElement.clientWidth;
            var login = document.getElementsByClassName("login")[0];
            login.style.left = clientWidth/2 - 200 + "px";
            login.style.top = clientHeight/2 - 150 + "px";
        }
    </script>

    效果

  • 相关阅读:
    SQL Server 2008 允许远程链接 解决方法
    对上传图片进行剪切的jquery插件
    解决在IE6 下,css中的position:fixed 不起作用的办法
    对网站搞评比投票活动的总结
    关于设置sql server 2008服务器属性时出现的无法加载xplog70.dll文件的问题
    Android LayoutInflater的使用
    在Android中查看和管理sqlite数据库
    android开发的WARNING: Could not initialize OpenglES emulation, using software renderer问题的解决
    Android 常用错误及解决方法
    解决MyEclipse启动速度慢,提高MyEclipse启动速度
  • 原文地址:https://www.cnblogs.com/douchenchen/p/6639214.html
Copyright © 2011-2022 走看看