码迷,mamicode.com
首页 > 其他好文 > 详细

登录注册弹窗

时间:2017-08-15 10:12:58      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:attribute   yellow   idt   res   doc   ack   body   html   登录注册   

代码如下

<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            * {
                margin: 0px;
                padding: 0px;
            }
            
            .login {
                width: 100px;
                height: 30px;
                font-size: 25px;
                line-height: 30px;
                border: 1px solid black;
                text-align: center;
                background-color: darkcyan;
                color: white;
            }
            
            .login:hover {
                cursor: pointer;
                background-color: greenyellow;
            }
            
            .mask {
                width: 100%;
                background-color: black;
                opacity: 0.5;
                position: absolute;
                top: 0px;
                left: 0px;
                z-index: 90;
            }
            
            .log-div {
                width: 500px;
                height: 300px;
                background-color: white;
                position: fixed;
                z-index: 99;
            }
        </style>
    </head>

    <body>
        <div class="mask" hidden></div>
        <div class="log-div" hidden="hidden"></div>
        <div class="login">登 录</div>
        <p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p>
        <p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p>
        <p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p>
        <p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p>


    </body>

</html>

<script>
    var mask = document.getElementsByClassName("mask")[0];
    var login = document.getElementsByClassName("log-div")[0];
    var btn = document.getElementsByClassName("login")[0];

    var clientWidth = document.body.clientWidth;
    var clientHeight = document.documentElement.clientHeight;

    login.style.left = clientWidth / 2 - 250 + "px";
    login.style.top = clientHeight / 2 - 150 + "px";
    
    mask.style.height = document.body.clientHeight + "px";

    window.onresize = function() {
        var clientWidth = document.body.clientWidth;
        var clientHeight = document.documentElement.clientHeight;

        login.style.left = clientWidth / 2 - 250 + "px";
        login.style.top = clientHeight / 2 - 150 + "px";
    }
    
    btn.onclick = function(){
        mask.removeAttribute("hidden");
        login.removeAttribute("hidden");
    }
    
    mask.onclick = function(){
        mask.setAttribute("hidden","");
        login.setAttribute("hidden","hidden");
    }
</script>

  

登录注册弹窗

标签:attribute   yellow   idt   res   doc   ack   body   html   登录注册   

原文地址:http://www.cnblogs.com/sglq/p/7363124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!