<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        a {
            text-decoration: none;
            color: #000;
        }

        .clearfix::after,
        .clearfix:before {
            content: '';
            display: table;
            clear: both;
        }

        .login {
            display: none;
            width: 512px;
            height: 280px;
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            background-color: #fff;
            box-shadow: 0 0 10px #ddd;
            z-index: 9999;
        }

        .login-title {
            width: 100%;
            line-height: 40px;
            font-size: 18px;
            text-align: center;
            margin-top: 10px;
            position: relative;
            cursor: move;
        }

        .login-title span {
            position: absolute;
            right: -20px;
            top: -30px;
            background-color: #fff;
            border: 1px solid #ebebeb;
            width: 40px;
            height: 40px;
            border-radius: 20px;
            font-size: 12px;
        }

        .login-input-content {
            margin-top: 20px;
        }

        .login-input {
            overflow: hidden;
            margin-bottom: 20px;
        }

        .login-input input.list-input {
            line-height: 35px;
            width: 350px;
            border: 1px solid #ebebeb;
            text-indent: 5px;
        }

        .login-input label {
            float: left;
            width: 90px;
            font-size: 14px;
            padding-right: 10px;
            text-align: right;
            line-height: 35px;
        }

        .login-button {
            width: 50%;
            line-height: 40px;
            border: 1px solid #ebebeb;
            text-align: center;
            margin: 30px auto 0 auto;
        }

        .login-button a {
            display: block;
        }

        .login-bg {
            display: none;
            width: 100%;
            height: 100%;
            position: fixed;
            left: 0;
            top: 0;
            background-color: rgba(0,0,0,0.3);
        }
    </style>
</head>
<body>
    <div class="login-header"><a href="javascript:;" id="link">点击,弹出登录框</a></div>
    <div id="login" class="login">
        <div id="title" class="login-title">登录会员
            <span><a href="javascript:;" class="close-login">关闭</a></span>
        </div>
        <div class="login-input-content">
            <div class="login-input">
                <label for="">用户名:</label>
                <input type="text" name="info[username]" placeholder="请输入用户名" id="username" class="list-input">
            </div>
            <div class="login-input">
                <label for="">密码:</label>
                <input type="password" name="info[password]" placeholder="请输入密码" id="password" class="list-input">
            </div>
        </div>
        <div id="loginBtn" class="clearfix login-button"><a href="javascript:;" id="login-button-submit">登录会员</a></div>
    </div>
    <div id="bg" class="login-bg"></div>
    <script>
        var login = document.querySelector('.login');
        var mask = document.querySelector('.login-bg')
        var link = document.querySelector('#link');
        var closeBtn = document.querySelector('.close-login');
        var title = document.querySelector('#title');
        link.addEventListener('click',function(){
            mask.style.display = 'block';
            login.style.display ='block';
        })
        closeBtn.addEventListener('click',function(){
            mask.style.display = 'none';
            login.style.display = 'none';
        })
        title.addEventListener('mousedown',function(e){
            var x = e.pageX - login.offsetLeft;
            var y = e.pageY - login.offsetTop;
            document.addEventListener('mousemove',move);
            function move(e) {
                login.style.left = e.pageX-x+'px';
                login.style.top = e.pageY - y + 'px';
            }
            document.addEventListener('mouseup',function(){
                document.removeEventListener('mousemove',move);
            })
        });

    </script>
</body>
</html>