弹出框组件

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

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

        .click_button {
            position: absolute;
            left: 45%;
        }

        .background {
            display: none;
            position: fixed;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, .3);
        }

        .login {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 400px;
            height: 200px;
            text-align: center;
            background-color: #fff;
            box-shadow: 0px 0px 20px #ddd;
            z-index: 3;
            transform: translate(-50%, -50%);
        }

        .login h3 {
            width: 100%;
            height: 40px;
            line-height: 40px;
            margin: 10px 0;
            cursor: move;
        }

        .login .username {
            margin-bottom: 10px;
        }

        .login input {
            height: 25px;
            margin-left: 10px;
            padding-left: 10px;
        }

        .login .password {
            margin-bottom: 10px;
            margin-left: -14px;
        }

        .login_botton {
            display: block;
            margin: 20px auto;
            width: 50%;
            height: 40px;
            line-height: 40px;
            border: #ebebeb 1px solid;
        }

        .login .close_button {
            position: absolute;
            width: 40px;
            height: 40px;
            line-height: 40px;
            background-color: #fff;
            font-size: 12px;
            right: -20px;
            top: -30px;
            border: #ebebeb solid 1px;
            border-radius: 20px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <a href="javascript:;" class="click_button">点击,弹出登录框</a>
    <div class="background">
        <div class="login">
            <h3 class="title">登陆会员</h3>
            <div class="username">
                <span>用户名:</span>
                <input type="text" placeholder="请输入用户名">
            </div>
            <div class="password">
                <span>登陆密码:</span>
                <input type="password" placeholder="请输入登陆密码">
            </div>
            <a href="javascript:;" class="login_botton">登陆会员</a>
            <span class="close_button">关闭</span>
        </div>
    </div>
    <script>
        var click_button = document.querySelector('.click_button');
        var bg = document.querySelector('.background');
        var close_button = document.querySelector('.close_button');
        var title = document.querySelector('.title');
        var login = document.querySelector('.login')
        // 2. 点击弹出层的按钮 弹出登录框
        click_button.addEventListener('click', function () {
            bg.style.display = 'block';
        });
        // 
        close_button.addEventListener('click', function () {
            bg.style.display = 'none';
        });

        // (1)当我们按下鼠标 获得鼠标在盒子内的坐标
        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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值